Skip to content

Type is int in boolean logic with sys.flags #12099

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

Closed
Dreamsorcerer opened this issue Jan 30, 2022 · 2 comments
Closed

Type is int in boolean logic with sys.flags #12099

Dreamsorcerer opened this issue Jan 30, 2022 · 2 comments
Labels
bug mypy got something wrong

Comments

@Dreamsorcerer
Copy link
Contributor

Dreamsorcerer commented Jan 30, 2022

a: bool
b: int
reveal_type(a or not b)  # Revealed type is "builtins.bool"
reveal_type(sys.flags.dev_mode or not sys.flags.ignore_environment)  # Revealed type is "builtins.int"

I can find no reason why this should be interpreted as int. dev_mode is bool and ignore_environment is int. The not will convert the int to a bool, as correctly inferred in the first example.

Code from here: https://github.com/aio-libs/aiohttp/pull/6549/files#diff-b797dd8733928df191ba2061121ab8b69976c185fcbfad4534891d3252b9ac30R84

@Dreamsorcerer Dreamsorcerer added the bug mypy got something wrong label Jan 30, 2022
@AlexWaygood
Copy link
Member

AlexWaygood commented Jan 30, 2022

sys.flags.dev_mode was previously incorrectly annotated as int in the typeshed stubs, but this has recently been corrected (python/typeshed#6816). The change has yet to be reflected in mypy, but should be fixed after the next typeshed sync.

@Dreamsorcerer
Copy link
Contributor Author

Ah, great, thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

No branches or pull requests

2 participants