mypy icon indicating copy to clipboard operation
mypy copied to clipboard

[used before def] rework builtin handling

Open ilinum opened this issue 3 years ago • 1 comments

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.

ilinum avatar Jan 21 '23 02:01 ilinum

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]

github-actions[bot] avatar Jan 21 '23 02:01 github-actions[bot]

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]

github-actions[bot] avatar Jan 23 '23 16:01 github-actions[bot]