mypy icon indicating copy to clipboard operation
mypy copied to clipboard

Used before def false positive when aliasing builtin definition

Open JukkaL opened this issue 3 years ago • 0 comments

The first error is a false positive, since range is available in builtins:

_range = range  # error: Name "range" is used before definition

_C = C  # error: Name "C" is used before definition

class range:
    pass

class C:
    pass

This is not reported consistently. In this case there is no error:

_range = range  # No error!

class range:
    pass

I assume the error is only generated when we perform two or more semantic analysis passes.

This is a regression introduced in #14166.

JukkaL avatar Jan 20 '23 13:01 JukkaL