Commits
Click on a commit to change the comparison range[`pyupgrade`] Allow shadowing non-builtin bindings (`UP029`)
Summary
--
I thought the fix unsafety example in the rule docs looked a bit suspicious
while I was going through more potential default rules today:
```py
def str(x):
return x
from builtins import str
str(1) # `"1"` with the import, `1` without
```
Changing the behavior in this way seemed to go beyond fix unsafety and into bug
territory. Sure enough, there was an existing bug report in #16182.
This PR fixes #16182 (and the fix safety example) by checking that the builtin
import that the rule flags is actually shadowing a builtin binding. I also left
an exception for `from builtins import *`, but we could consider ignoring that
case too.
I initially tried reusing `SemanticModel::resolve_name` and `only_binding`, but
they are specific to `ExprName`s because that seems to be all that is inserted
into the `SemanticModel::resolved_names` map.
Test Plan
--
New tests based on #16182 and the fix safety docs