Skip to content

Used before def false positive when aliasing builtin definition #14476

@JukkaL

Description

@JukkaL

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrongfalse-positivemypy gave an error on correct codetopic-possibly-undefinedpossibly-undefined error code

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions