Skip to content

Fix base class compatibility for IntFlag in Python 3.11+ to resolve inverted type issue #13854

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

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

Conversation

vidhyavijayan3
Copy link

@vidhyavijayan3 vidhyavijayan3 commented Apr 19, 2025

  • Updated the IntFlag class definition to ensure compatibility with Python 3.11+ by adjusting base classes.
  • Fixed the type mismatch issue by properly aligning base classes for the IntFlag class, which resolves the incorrect type for the inverted IntFlag.
  • This change ensures proper behavior and type resolution across different Python versions.

Fixes #13853

This comment has been minimized.

stdlib/enum.pyi Outdated
@@ -299,6 +299,7 @@ if sys.version_info >= (3, 11):
def __or__(self, other: int) -> Self: ...
def __and__(self, other: int) -> Self: ...
def __xor__(self, other: int) -> Self: ...
def __invert__(self) -> IntFlag: ...
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def __invert__(self) -> IntFlag: ...
def __invert__(self) -> Self: ...

stdlib/enum.pyi Outdated
@@ -309,6 +310,7 @@ else:
def __or__(self, other: int) -> Self: ...
def __and__(self, other: int) -> Self: ...
def __xor__(self, other: int) -> Self: ...
def __invert__(self) -> IntFlag: ...
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
def __invert__(self) -> IntFlag: ...
def __invert__(self) -> Self: ...

Copy link
Author

Choose a reason for hiding this comment

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

Thanks for the suggestion! @brianschubert I've made the changes you recommended.

Copy link
Contributor

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

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.

Invalid type for inverted IntFlag
2 participants