Skip to content

[Bug]: FURB143 suggesting change that isn't compatible with the context of code #283

@owenlamont

Description

@owenlamont

Has your issue already been fixed?

  • Have you checked to see if your issue still exists on the master branch? See the docs for instructions on how to setup a local build of Refurb.
  • Have you looked at the open/closed issues to see if anyone has already reported your issue?

The Bug

The following code:

abbreviation: str | None = None
word = "blah"
abbreviation = (abbreviation or "") + word

Emits the following error:

$ refurb file.py
# example.py:31:25 [FURB143]: Replace `x or ""` with `x`

But it should not be emitting an error instance because...

The recommended code change will break the code when the input string is None as None type and string can't be concatenated.

Version Info

Refurb: v1.20.0

Python Version

3.11.4

Config File

[tool.refurb]
ignore = [
    "FURB124", # Ignore rule to recommend chaining comparisons over anding pairs
    "FURB140" # Ignore rule to prefer starmap when iterating and constructing
]
python_version = "3.9"

Extra Info

I hacked the actual example line to be more minimal but this is my example of rule FURB143 being incorrectly applied where coercing a None to a string makes sense and it isn't simply mapping one falsey type to another as the recommended change would break the code.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions