From 70c10891d681bdb19a448e9fb5fcd1880d8732a2 Mon Sep 17 00:00:00 2001 From: Ujan RoyBandyopadhyay <116058173+ujan-r@users.noreply.github.com> Date: Mon, 14 Aug 2023 16:12:19 -0500 Subject: [PATCH 1/8] Update enum __dir__ docs with changes from 3.11 --- Doc/howto/enum.rst | 8 ++++++-- Doc/library/enum.rst | 17 ++++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/Doc/howto/enum.rst b/Doc/howto/enum.rst index 4312b4c8140f5c..2a26b81fe875a3 100644 --- a/Doc/howto/enum.rst +++ b/Doc/howto/enum.rst @@ -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. Combining members of ``Flag`` diff --git a/Doc/library/enum.rst b/Doc/library/enum.rst index e9c4f0e2c5f59b..300433ec4bdfbf 100644 --- a/Doc/library/enum.rst +++ b/Doc/library/enum.rst @@ -207,12 +207,16 @@ Data Types .. method:: EnumType.__dir__(cls) - Returns ``['__class__', '__doc__', '__members__', '__module__']`` and the - names of the members in *cls*:: + Returns ``['__class__', '__contains__', '__doc__', '__getitem__', '__iter__', '__len__', '__members__', '__module__', '__name__', '__qualname__']`` + and the names of the members in *cls*:: >>> dir(Color) ['BLUE', 'GREEN', 'RED', '__class__', '__contains__', '__doc__', '__getitem__', '__init_subclass__', '__iter__', '__len__', '__members__', '__module__', '__name__', '__qualname__'] + .. versionchanged:: 3.11 + '__contains__', '__getitem__', '__iter__', '__len__', '__name__', and + '__qualname__' are also returned. + .. method:: EnumType.__getitem__(cls, name) Returns the Enum member in *cls* matching *name*, or raises a :exc:`KeyError`:: @@ -278,8 +282,8 @@ Data Types .. method:: Enum.__dir__(self) - Returns ``['__class__', '__doc__', '__module__', 'name', 'value']`` and - any public methods defined on *self.__class__*:: + Returns ``['__class__', '__doc__', '__eq__', '__hash__', '__module__', 'name', 'value']``, + enum members, and any public methods defined on *self.__class__*:: >>> from datetime import date >>> class Weekday(Enum): @@ -295,7 +299,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) From 77269f83a43569593ad127b71da4f93ecbe70d9e Mon Sep 17 00:00:00 2001 From: Ujan RoyBandyopadhyay <116058173+ujan-r@users.noreply.github.com> Date: Mon, 14 Aug 2023 16:15:23 -0500 Subject: [PATCH 2/8] Enable previously skipped doctests --- Doc/howto/enum.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/howto/enum.rst b/Doc/howto/enum.rst index 2a26b81fe875a3..8b90ca7dbd4d15 100644 --- a/Doc/howto/enum.rst +++ b/Doc/howto/enum.rst @@ -1050,9 +1050,9 @@ If you give your enum subclass extra methods, like the `Planet`_ class below, those methods will show up in a :func:`dir` of the member, but not of the class:: - >>> dir(Planet) # doctest: +SKIP + >>> dir(Planet) ['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 + >>> dir(Planet.EARTH) ['EARTH', 'JUPITER', 'MARS', 'MERCURY', 'NEPTUNE', 'SATURN', 'URANUS', 'VENUS', '__class__', '__doc__', '__eq__', '__hash__', '__module__', 'mass', 'name', 'radius', 'surface_gravity', 'value'] .. versionchanged:: 3.11 From 0dc0ab7621309400ed215fbff6cfd4fcdd30abd4 Mon Sep 17 00:00:00 2001 From: Ujan RoyBandyopadhyay <116058173+ujan-r@users.noreply.github.com> Date: Mon, 14 Aug 2023 17:06:48 -0500 Subject: [PATCH 3/8] Remove unnecessary 'versionchanged' note --- Doc/library/enum.rst | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Doc/library/enum.rst b/Doc/library/enum.rst index 300433ec4bdfbf..52a197807fa3e1 100644 --- a/Doc/library/enum.rst +++ b/Doc/library/enum.rst @@ -213,10 +213,6 @@ Data Types >>> dir(Color) ['BLUE', 'GREEN', 'RED', '__class__', '__contains__', '__doc__', '__getitem__', '__init_subclass__', '__iter__', '__len__', '__members__', '__module__', '__name__', '__qualname__'] - .. versionchanged:: 3.11 - '__contains__', '__getitem__', '__iter__', '__len__', '__name__', and - '__qualname__' are also returned. - .. method:: EnumType.__getitem__(cls, name) Returns the Enum member in *cls* matching *name*, or raises a :exc:`KeyError`:: From 20cbcd396924895630a19e7dfec6965f94ba6041 Mon Sep 17 00:00:00 2001 From: Ujan RoyBandyopadhyay <116058173+ujan-r@users.noreply.github.com> Date: Mon, 14 Aug 2023 20:39:52 -0500 Subject: [PATCH 4/8] Update ACKS and add blurb --- Misc/ACKS | 1 + .../Documentation/2023-08-14-20-38-39.gh-issue-107957.DU3mID.rst | 1 + 2 files changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Documentation/2023-08-14-20-38-39.gh-issue-107957.DU3mID.rst diff --git a/Misc/ACKS b/Misc/ACKS index 8b8c5ad8434bd7..1624ded7a17449 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1562,6 +1562,7 @@ Liam Routt Todd Rovito Craig Rowland Clinton Roy +Ujan RoyBandyopadhyay Paul Rubin Sam Ruby Demur Rumed diff --git a/Misc/NEWS.d/next/Documentation/2023-08-14-20-38-39.gh-issue-107957.DU3mID.rst b/Misc/NEWS.d/next/Documentation/2023-08-14-20-38-39.gh-issue-107957.DU3mID.rst new file mode 100644 index 00000000000000..168706de2f31f2 --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2023-08-14-20-38-39.gh-issue-107957.DU3mID.rst @@ -0,0 +1 @@ +Fix sample outputs for :func:`dir()` function in :module:`enum` docs. From 98d0f2df02587e0b90416a820d5872ba7086c780 Mon Sep 17 00:00:00 2001 From: Ujan RoyBandyopadhyay <116058173+ujan-r@users.noreply.github.com> Date: Mon, 14 Aug 2023 20:54:13 -0500 Subject: [PATCH 5/8] Fix typo in blurb --- .../2023-08-14-20-38-39.gh-issue-107957.DU3mID.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Documentation/2023-08-14-20-38-39.gh-issue-107957.DU3mID.rst b/Misc/NEWS.d/next/Documentation/2023-08-14-20-38-39.gh-issue-107957.DU3mID.rst index 168706de2f31f2..fa5786fbe809e3 100644 --- a/Misc/NEWS.d/next/Documentation/2023-08-14-20-38-39.gh-issue-107957.DU3mID.rst +++ b/Misc/NEWS.d/next/Documentation/2023-08-14-20-38-39.gh-issue-107957.DU3mID.rst @@ -1 +1 @@ -Fix sample outputs for :func:`dir()` function in :module:`enum` docs. +Fix sample outputs for :func:`dir()` function in :mod:`enum` docs. From 2e067a4b06d03fa62db3924b51780fd4e5e38233 Mon Sep 17 00:00:00 2001 From: Ujan RoyBandyopadhyay <116058173+ujan-r@users.noreply.github.com> Date: Mon, 14 Aug 2023 22:08:31 -0500 Subject: [PATCH 6/8] Move interesting names before dunder/special names --- Doc/library/enum.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Doc/library/enum.rst b/Doc/library/enum.rst index 52a197807fa3e1..caf9fc3194b6c9 100644 --- a/Doc/library/enum.rst +++ b/Doc/library/enum.rst @@ -207,8 +207,8 @@ Data Types .. method:: EnumType.__dir__(cls) - Returns ``['__class__', '__contains__', '__doc__', '__getitem__', '__iter__', '__len__', '__members__', '__module__', '__name__', '__qualname__']`` - 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__'] @@ -278,8 +278,8 @@ Data Types .. method:: Enum.__dir__(self) - Returns ``['__class__', '__doc__', '__eq__', '__hash__', '__module__', 'name', 'value']``, - enum members, 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): From 848dd1820fa3963513f3a3d5464f6f15a06d34e3 Mon Sep 17 00:00:00 2001 From: Ujan RoyBandyopadhyay <116058173+ujan-r@users.noreply.github.com> Date: Mon, 14 Aug 2023 22:40:00 -0500 Subject: [PATCH 7/8] Remove NEWS --- .../Documentation/2023-08-14-20-38-39.gh-issue-107957.DU3mID.rst | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Misc/NEWS.d/next/Documentation/2023-08-14-20-38-39.gh-issue-107957.DU3mID.rst diff --git a/Misc/NEWS.d/next/Documentation/2023-08-14-20-38-39.gh-issue-107957.DU3mID.rst b/Misc/NEWS.d/next/Documentation/2023-08-14-20-38-39.gh-issue-107957.DU3mID.rst deleted file mode 100644 index fa5786fbe809e3..00000000000000 --- a/Misc/NEWS.d/next/Documentation/2023-08-14-20-38-39.gh-issue-107957.DU3mID.rst +++ /dev/null @@ -1 +0,0 @@ -Fix sample outputs for :func:`dir()` function in :mod:`enum` docs. From 722550f257394eeb08e10e6b39d30ddfbc4dfc5c Mon Sep 17 00:00:00 2001 From: Ujan RoyBandyopadhyay <116058173+ujan-r@users.noreply.github.com> Date: Wed, 16 Aug 2023 00:31:20 -0500 Subject: [PATCH 8/8] Revert commit enabling doctests --- Doc/howto/enum.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/howto/enum.rst b/Doc/howto/enum.rst index 8b90ca7dbd4d15..2a26b81fe875a3 100644 --- a/Doc/howto/enum.rst +++ b/Doc/howto/enum.rst @@ -1050,9 +1050,9 @@ If you give your enum subclass extra methods, like the `Planet`_ class below, those methods will show up in a :func:`dir` of the member, but not of the class:: - >>> dir(Planet) + >>> dir(Planet) # doctest: +SKIP ['EARTH', 'JUPITER', 'MARS', 'MERCURY', 'NEPTUNE', 'SATURN', 'URANUS', 'VENUS', '__class__', '__contains__', '__doc__', '__getitem__', '__init_subclass__', '__iter__', '__len__', '__members__', '__module__', '__name__', '__qualname__'] - >>> dir(Planet.EARTH) + >>> dir(Planet.EARTH) # doctest: +SKIP ['EARTH', 'JUPITER', 'MARS', 'MERCURY', 'NEPTUNE', 'SATURN', 'URANUS', 'VENUS', '__class__', '__doc__', '__eq__', '__hash__', '__module__', 'mass', 'name', 'radius', 'surface_gravity', 'value'] .. versionchanged:: 3.11