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

Fix for type narrowing of negative integer literals #17256

Merged
merged 1 commit into from
May 17, 2024

Conversation

gilesgc
Copy link
Contributor

@gilesgc gilesgc commented May 17, 2024

Fixes #10514
Fixes #17118

Negative integer literals were not being correctly handled in the type narrowing process, causing mypy errors such as "Statement is unreachable" despite the checked code being valid. This fix ensures that negative integer literals are properly considered in if-statements.

Fixes type narrowing for negative integer literals
Copy link
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@JelleZijlstra JelleZijlstra merged commit b74829e into python:master May 17, 2024
18 checks passed
@JelleZijlstra
Copy link
Member

Great find, thank you!

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

Successfully merging this pull request may close these issues.

Missing type narrowing with Literal[-1] Type narrowing broken with negative integer literals
2 participants