-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
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
base: main
Are you sure you want to change the base?
gh-135559: Include named aliases in dir() for IntFlag instances #135584
Conversation
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 |
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 |
@@ -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(): |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
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.