mypy
mypy copied to clipboard
[used before def] rework builtin handling
When doing multiple passes, in the example below, range will refer to current's module range. When doing a single pass, range will refer to builtins.range:
_range = range
_C = C # error: Name "C" is used before definition
class range: pass
class C: pass
Instead of looking at the output of semanal to check if a variable is resolving to a builtins package, we can just check if it's part of builtins module.
Fixes #14476.
Diff from mypy_primer, showing the effect of this PR on open source code:
spark (https://github.com/apache/spark)
- python/pyspark/pandas/namespace.py:159: error: Name "range" is used before definition [used-before-def]
Diff from mypy_primer, showing the effect of this PR on open source code:
spark (https://github.com/apache/spark)
- python/pyspark/pandas/namespace.py:159: error: Name "range" is used before definition [used-before-def]