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

False positive F811 when using TYPE_CHECKING #5561

Closed
phil65 opened this issue Jul 6, 2023 · 3 comments
Closed

False positive F811 when using TYPE_CHECKING #5561

phil65 opened this issue Jul 6, 2023 · 3 comments
Labels
bug Something isn't working

Comments

@phil65
Copy link

phil65 commented Jul 6, 2023

For following code

from typing import TYPE_CHECKING:
...
if TYPE_CHECKING:
    from x import y

...

if __name__ == "__main__":
    from x import y
    ...

Error F811 gets reported, which should not be the case I think.
Thank you for this great tool!

@phil65 phil65 changed the title False positive False positive F811 when using TYPE_CHECKING Jul 6, 2023
@zanieb
Copy link
Member

zanieb commented Jul 6, 2023

Thanks for the issue! This indeed looks incorrect. Since this is just a small example, I'm curious why you're using this pattern in the real world?

Regardless, it seems like from x import y should be allowed in a new scope if the previous import was in an if-type-checking block.

You would expect the following to get reported still, right?

from typing import TYPE_CHECKING:

if TYPE_CHECKING:
    from x import y

from x import y

@zanieb zanieb added the bug Something isn't working label Jul 6, 2023
@phil65
Copy link
Author

phil65 commented Jul 6, 2023

Yes, I would expect that to get reported.
I am often using the if __name__ == "__main__": section for testing purposes, that´s why I am using this pattern.

@charliermarsh
Copy link
Member

This no longer gets triggered (in the next version).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants