https://github.com/python/cpython/commit/26757d135143b9e481bafd1d477634bf327910a7
commit: 26757d135143b9e481bafd1d477634bf327910a7
branch: main
author: Ethan Furman <[email protected]>
committer: ethanfurman <[email protected]>
date: 2025-12-10T11:46:10-08:00
summary:

gh-135559: [Enum] dir() on a Flag now shows aliases (GH-136527)

files:
A Misc/NEWS.d/next/Library/2025-07-10-18-40-11.gh-issue-135559.BMDtYn.rst
M Lib/enum.py
M Lib/test/test_enum.py

diff --git a/Lib/enum.py b/Lib/enum.py
index ad782b8c41e160..15dddf6de69268 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -774,12 +774,16 @@ def __delattr__(cls, attr):
         super().__delattr__(attr)
 
     def __dir__(cls):
+        if issubclass(cls, Flag):
+            members = list(cls._member_map_.keys())
+        else:
+            members = cls._member_names_
         interesting = set([
                 '__class__', '__contains__', '__doc__', '__getitem__',
                 '__iter__', '__len__', '__members__', '__module__',
                 '__name__', '__qualname__',
                 ]
-                + cls._member_names_
+                + members
                 )
         if cls._new_member_ is not object.__new__:
             interesting.add('__new__')
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index 66d78980c41cb6..779457119e8f0e 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -5529,12 +5529,16 @@ def test_enum_dict_standalone(self):
 # helpers
 
 def enum_dir(cls):
+    if issubclass(cls, Flag):
+        members = list(cls._member_map_.keys())
+    else:
+        members = cls._member_names_
     interesting = set([
             '__class__', '__contains__', '__doc__', '__getitem__',
             '__iter__', '__len__', '__members__', '__module__',
             '__name__', '__qualname__',
             ]
-            + cls._member_names_
+            + members
             )
     if cls._new_member_ is not object.__new__:
         interesting.add('__new__')
diff --git 
a/Misc/NEWS.d/next/Library/2025-07-10-18-40-11.gh-issue-135559.BMDtYn.rst 
b/Misc/NEWS.d/next/Library/2025-07-10-18-40-11.gh-issue-135559.BMDtYn.rst
new file mode 100644
index 00000000000000..2ab3d4d76f38e8
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2025-07-10-18-40-11.gh-issue-135559.BMDtYn.rst
@@ -0,0 +1,2 @@
+Flag: a ``dir()`` on a ``Flag`` enumeration now shows non-canonical members.
+(i.e. aliases).

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3//lists/python-checkins.python.org
Member address: [email protected]

Reply via email to