Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
update code to match documentation
  • Loading branch information
ethanfurman committed Oct 23, 2023
commit 766639a858fdd3569d38db6e473202a8a462a1e9
4 changes: 2 additions & 2 deletions Doc/howto/enum.rst
Original file line number Diff line number Diff line change
Expand Up @@ -772,8 +772,8 @@ be combined with them (but may lose :class:`IntFlag` membership::
>>> Perm.X | 4
<Perm.R|X: 5>

>>> Perm.X | 8
<Perm.X|8: 9>
>>> Perm.X + 8
9

.. note::

Expand Down
2 changes: 1 addition & 1 deletion Doc/library/enum.rst
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ Data Types
... print('today is %s' % cls(date.today().isoweekday()).name)
...
>>> dir(Weekday.SATURDAY)
['FRIDAY', 'MONDAY', 'SATURDAY', 'SUNDAY', 'THURSDAY', 'TUESDAY', 'WEDNESDAY', '__class__', '__doc__', '__eq__', '__hash__', '__module__', 'name', 'today', 'value']
['__class__', '__doc__', '__eq__', '__hash__', '__module__', 'name', 'today', 'value']

.. method:: Enum._generate_next_value_(name, start, count, last_values)

Expand Down
11 changes: 5 additions & 6 deletions Lib/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -1189,14 +1189,13 @@ def __str__(self):

def __dir__(self):
"""
Returns all members and all public methods
Returns public methods and other interesting attributes.
"""
if self.__class__._member_type_ is object:
interesting = set(['__class__', '__doc__', '__eq__', '__hash__', '__module__', 'name', 'value'])
else:
interesting = set()
if self.__class__._member_type_ is not object:
interesting = set(object.__dir__(self))
for name in getattr(self, '__dict__', []):
if name[0] != '_':
if name[0] != '_' and name not in self._member_map_:
interesting.add(name)
for cls in self.__class__.mro():
for name, obj in cls.__dict__.items():
Expand All @@ -1209,7 +1208,7 @@ def __dir__(self):
else:
# in case it was added by `dir(self)`
interesting.discard(name)
else:
elif name not in self._member_map_:
interesting.add(name)
names = sorted(
set(['__class__', '__doc__', '__eq__', '__hash__', '__module__'])
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -5171,7 +5171,7 @@ def member_dir(member):
allowed.add(name)
else:
allowed.discard(name)
else:
elif name not in member._member_map_:
allowed.add(name)
return sorted(allowed)

Expand Down