mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-45535: Improve output of Enum `dir()
` (GH-29316)
Modify the ``EnumType.__dir__()`` and ``Enum.__dir__()`` to ensure that user-defined methods and methods inherited from mixin classes always show up in the output of `help()`. This change also makes it easier for IDEs to provide auto-completion.
This commit is contained in:
parent
cb8f491f46
commit
b2afdc95cc
5 changed files with 386 additions and 53 deletions
|
@ -997,11 +997,12 @@ Plain :class:`Enum` classes always evaluate as :data:`True`.
|
|||
"""""""""""""""""""""""""""""
|
||||
|
||||
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::
|
||||
class below, those methods will show up in a :func:`dir` of the member and the
|
||||
class. Attributes defined in an :func:`__init__` method will only show up in a
|
||||
:func:`dir` of the member::
|
||||
|
||||
>>> dir(Planet)
|
||||
['EARTH', 'JUPITER', 'MARS', 'MERCURY', 'NEPTUNE', 'SATURN', 'URANUS', 'VENUS', '__class__', '__doc__', '__members__', '__module__']
|
||||
['EARTH', 'JUPITER', 'MARS', 'MERCURY', 'NEPTUNE', 'SATURN', 'URANUS', 'VENUS', '__class__', '__doc__', '__init__', '__members__', '__module__', 'surface_gravity']
|
||||
>>> dir(Planet.EARTH)
|
||||
['__class__', '__doc__', '__module__', 'mass', 'name', 'radius', 'surface_gravity', 'value']
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue