jendrikseipp / vulture

Find dead Python code
MIT License
3.41k stars 150 forks source link

Treat `getattr(obj, "constant_string", default)` as a reference to `obj.constant_string` #219

Closed jingw closed 4 years ago

jingw commented 4 years ago

Description

I realize handling getattr is a slippery slope. I think this case makes sense and is a reasonable place to draw the line.

My rationale is that the following code does the same thing, counts as a reference to obj.constant_string, but is not what most people would write.

try:
    x = obj.constant_string
except AttributeError:
    x = None

Related Issue

Haven't filed one. Happy to discuss this makes sense or not.

Checklist:

jendrikseipp commented 4 years ago

Thanks for the patch!