Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

used-before-def and TYPE_CHECKING #15314

Closed
JelleZijlstra opened this issue May 26, 2023 · 1 comment
Closed

used-before-def and TYPE_CHECKING #15314

JelleZijlstra opened this issue May 26, 2023 · 1 comment
Labels
bug mypy got something wrong topic-possibly-undefined possibly-undefined error code

Comments

@JelleZijlstra
Copy link
Member

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    Alias = MyClass
else:
    Alias = object
    
class MyClass:
    pass

On mypy 1.3.0 (https://mypy-play.net/?mypy=latest&python=3.10&gist=5f2c9b8d93c4b97a57d385c3511f23b3) produces:

main.py:4: error: Name "MyClass" is used before definition  [used-before-def]

Perhaps the check should be fully suppressed within if TYPE_CHECKING blocks.

@JelleZijlstra JelleZijlstra added bug mypy got something wrong topic-possibly-undefined possibly-undefined error code labels May 26, 2023
@JelleZijlstra
Copy link
Member Author

This is a duplicate of #14539.

@JelleZijlstra JelleZijlstra closed this as not planned Won't fix, can't repro, duplicate, stale Jun 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-possibly-undefined possibly-undefined error code
Projects
None yet
Development

No branches or pull requests

1 participant