FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-107957: Fix `dir()` sample output in `enum` docs by ujan-r · Pull Request #107958 · python/cpython · GitHub

Repository navigation

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .rst  (2) No extension  (1) All 2 file types selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
8 changes: 6 additions & 2 deletions Doc/howto/enum.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
Comment thread
ujan-r marked this conversation as resolved.
['__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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
Copy Markdown
Author

Choose a reason for hiding this comment

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

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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

Back | FazBrowse Home | New Git URL