Skip to content

gh-135559: Include named aliases in dir() for IntFlag instances #135584

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

lokhandelokeek11
Copy link

@lokhandelokeek11 lokhandelokeek11 commented Jun 16, 2025

This PR fixes issue [#135559]

Previously, dir() on IntFlag instances omitted named aliases (e.g., READ_WRITE = READ | WRITE).
This change updates the dir method in enum.py to include all named members, including aliases, by checking members where name is not None.
Also added a test in test_enum.py to validate the behavior.
I wasn’t able to run the full test suite locally due to build setup issues @ethanfurman, but the logic is isolated and verified through reasoning and test inclusion.

@python-cla-bot
Copy link

python-cla-bot bot commented Jun 16, 2025

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Jun 16, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@bedevere-app
Copy link

bedevere-app bot commented Jun 16, 2025

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@ZeroIntensity ZeroIntensity changed the title Fix Issue #135559: Include named aliases in dir() for IntFlag instances gh-135559: Include named aliases in dir() for IntFlag instances Jun 16, 2025
@@ -1120,6 +1120,13 @@ def test_shadowed_attr(self):
class TestIntFlagClass(_EnumTests, _MinimalOutputTests, _FlagTests, unittest.TestCase):
enum_type = IntFlag

def test_dir_includes_named_aliases():
Copy link
Member

Choose a reason for hiding this comment

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

This won't work :(
Since we use unittest and not pytest. Please, rewrite this test.

WRITE = 2
READ_WRITE = READ | WRITE

assert 'READ_WRITE' in dir(MyFlags.READ_WRITE)
Copy link
Member

Choose a reason for hiding this comment

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

We use self.assert* methods here.
Please, add checks for all related names, not only a single one.

I would propose to add more combitations of values to the test.

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

Successfully merging this pull request may close these issues.

2 participants