dosisod / refurb

A tool for refurbishing and modernizing Python codebases
GNU General Public License v3.0
2.48k stars 54 forks source link

[Bug]: Suggests to replace len(text) with text in `if len(text) % 2` #318

Closed tiagocoutinho closed 10 months ago

tiagocoutinho commented 10 months ago

Has your issue already been fixed?

The Bug

The following code:

def f(text):
    if len(text) % 2:
        return 1
    return 0

Emits the following suggestion:

$ refurb file.py
file.py:2:7 [FURB115]: Replace `len(text)` with `text`

but it shouldn't because the resulting code would raise TypeError

Version Info

Refurb: v1.25.0
Mypy: v1.7.1

Python Version

Python 3.10.13

Config File

# N/A

Extra Info

None

dosisod commented 10 months ago

Thank you @tiagocoutinho for opening this!