Skip to content
New issue

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

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

Already on GitHub? # to your account

Narrow literals in the negative case even with custom equality #18574

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

A5rocks
Copy link
Collaborator

@A5rocks A5rocks commented Jan 30, 2025

Fixes #16465
Fixes #18029
Fixes #17229

Generally, people cannot replace a literal's equality. So negative narrowing is still safe. (not the case for enum literals, so those don't get this treatment)

if should_narrow_by_identity:
return True
else:
return not p_t.fallback.type.is_enum
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternative: I could try has_no_custom_eq_checks(p_t.fallback) maybe?

This comment has been minimized.

Copy link
Contributor

github-actions bot commented Feb 7, 2025

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
1 participant