gh-135559: Include named aliases in dir() for IntFlag instances#135584
gh-135559: Include named aliases in dir() for IntFlag instances#135584lokhandelokeek11 wants to merge 2 commits intopython:mainfrom
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 |
| class TestIntFlagClass(_EnumTests, _MinimalOutputTests, _FlagTests, unittest.TestCase): | ||
| enum_type = IntFlag | ||
|
|
||
| def test_dir_includes_named_aliases(): |
There was a problem hiding this comment.
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.
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.
|
Several weeks have passed with no communications from @lokhandelokeek11 and multiple problems with the PR. Closing. |
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.