Skip to content

gh-107957: Fix dir() sample output in enum docs #107958

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

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 6 additions & 2 deletions Doc/howto/enum.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1051,9 +1051,13 @@ class below, those methods will show up in a :func:`dir` of the member,
but not of the class::

>>> dir(Planet) # doctest: +SKIP
['EARTH', 'JUPITER', 'MARS', 'MERCURY', 'NEPTUNE', 'SATURN', 'URANUS', 'VENUS', '__class__', '__doc__', '__members__', '__module__']
['EARTH', 'JUPITER', 'MARS', 'MERCURY', 'NEPTUNE', 'SATURN', 'URANUS', 'VENUS', '__class__', '__contains__', '__doc__', '__getitem__', '__init_subclass__', '__iter__', '__len__', '__members__', '__module__', '__name__', '__qualname__']
>>> dir(Planet.EARTH) # doctest: +SKIP
['__class__', '__doc__', '__module__', 'mass', 'name', 'radius', 'surface_gravity', 'value']
['EARTH', 'JUPITER', 'MARS', 'MERCURY', 'NEPTUNE', 'SATURN', 'URANUS', 'VENUS', '__class__', '__doc__', '__eq__', '__hash__', '__module__', 'mass', 'name', 'radius', 'surface_gravity', 'value']

.. versionchanged:: 3.11
Additional ``__dunder__`` names are returned for enums and enum members.
Calling :func:`dir` on an enum member also returns the other members.
Comment on lines +1058 to +1060
Copy link
Member

Choose a reason for hiding this comment

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

We don't need versionchanged in a How To document

Suggested change
.. versionchanged:: 3.11
Additional ``__dunder__`` names are returned for enums and enum members.
Calling :func:`dir` on an enum member also returns the other members.

Copy link
Author

Choose a reason for hiding this comment

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

Should I remove it? Note that there are 13 other occurrences of versionadded/versionchanged in the document



Combining members of ``Flag``
Expand Down
13 changes: 8 additions & 5 deletions Doc/library/enum.rst
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ Data Types

.. method:: EnumType.__dir__(cls)

Returns ``['__class__', '__doc__', '__members__', '__module__']`` and the
names of the members in *cls*::
Returns the names of the members in *cls* and
``['__class__', '__contains__', '__doc__', '__getitem__', '__iter__', '__len__', '__members__', '__module__', '__name__', '__qualname__']``::

>>> dir(Color)
['BLUE', 'GREEN', 'RED', '__class__', '__contains__', '__doc__', '__getitem__', '__init_subclass__', '__iter__', '__len__', '__members__', '__module__', '__name__', '__qualname__']
Expand Down Expand Up @@ -278,8 +278,8 @@ Data Types

.. method:: Enum.__dir__(self)

Returns ``['__class__', '__doc__', '__module__', 'name', 'value']`` and
any public methods defined on *self.__class__*::
Returns the names of the enum members and any public methods defined on
*self.__class__*, as well as ``['__class__', '__doc__', '__eq__', '__hash__', '__module__', 'name', 'value']``::

>>> from datetime import date
>>> class Weekday(Enum):
Expand All @@ -295,7 +295,10 @@ Data Types
... print('today is %s' % cls(date.today().isoweekday()).name)
...
>>> dir(Weekday.SATURDAY)
['__class__', '__doc__', '__eq__', '__hash__', '__module__', 'name', 'today', 'value']
['FRIDAY', 'MONDAY', 'SATURDAY', 'SUNDAY', 'THURSDAY', 'TUESDAY', 'WEDNESDAY', '__class__', '__doc__', '__eq__', '__hash__', '__module__', 'name', 'today', 'value']

.. versionchanged:: 3.11
'__eq__', '__hash__', and enum members are also returned.

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

Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -1562,6 +1562,7 @@ Liam Routt
Todd Rovito
Craig Rowland
Clinton Roy
Ujan RoyBandyopadhyay
Paul Rubin
Sam Ruby
Demur Rumed
Expand Down