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

Merged
merged 2 commits into from
Apr 28, 2025

Conversation

vidhyavijayan3
Copy link
Contributor

@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
Contributor 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. 🤖🎉

@vidhyavijayan3
Copy link
Contributor Author

Hi @brianschubert

I've updated the invert return type from IntFlag to Self as suggested.
All checks have passed, and the change should now properly handle the inverted IntFlag type issue.
Is there anything else needed from my side to get this PR merged?
Thanks for your time and help!

Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

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

Thanks!

@srittau srittau merged commit 42347a1 into python:main Apr 28, 2025
55 checks passed
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
3 participants