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

Don't use equality to narrow when value is IntEnum/StrEnum #17866

Merged
merged 1 commit into from
Oct 2, 2024

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Oct 2, 2024

IntEnum/StrEnum values compare equal to the corresponding int/str values, which breaks the logic we use for narrowing based on equality to a literal value. Special case IntEnum/StrEnum to avoid the incorrect behavior.

Fix #17860.

IntEnum/StrEnum values compare equal to the corresponding int/str values,
which breaks the logic we use for narrowing based on equality to a
literal value. Special case IntEnum/StrEnum to avoid the incorrect
behavior.

Fix #17860.
Copy link
Contributor

github-actions bot commented Oct 2, 2024

Diff from mypy_primer, showing the effect of this PR on open source code:

optuna (https://github.com/optuna/optuna)
+ tests/storages_tests/test_heartbeat.py:72: error: Unused "type: ignore" comment  [unused-ignore]
+ tests/storages_tests/test_heartbeat.py:229: error: Unused "type: ignore" comment  [unused-ignore]

psycopg (https://github.com/psycopg/psycopg)
+ tests/test_pipeline_async.py:57: error: Unused "type: ignore" comment  [unused-ignore]
+ tests/test_pipeline.py:60: error: Unused "type: ignore" comment  [unused-ignore]

@JukkaL JukkaL merged commit aa7733a into master Oct 2, 2024
19 checks passed
@JukkaL JukkaL deleted the fix-enum-narrow branch October 2, 2024 15:45
JukkaL added a commit that referenced this pull request Oct 4, 2024
Fix regression in #17866. It should still be possible to narrow
IntEnum and StrEnum types, but only when types match or are
disjoint. Add more logic to rule out narrowing when types are
ambigous.
JukkaL added a commit that referenced this pull request Oct 4, 2024
Fix regression introduced in #17866. It should still be possible to
narrow IntEnum and StrEnum types, but only when types match or are
disjoint. Add more logic to rule out narrowing when types are ambigous.
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.

Integer incorrectly narrowed to IntEnum
2 participants