mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +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
|
@ -162,7 +162,8 @@ Data Types
|
|||
.. method:: EnumType.__dir__(cls)
|
||||
|
||||
Returns ``['__class__', '__doc__', '__members__', '__module__']`` and the
|
||||
names of the members in *cls*::
|
||||
names of the members in ``cls``. User-defined methods and methods from
|
||||
mixin classes will also be included::
|
||||
|
||||
>>> dir(Color)
|
||||
['BLUE', 'GREEN', 'RED', '__class__', '__doc__', '__members__', '__module__']
|
||||
|
@ -260,7 +261,7 @@ Data Types
|
|||
.. method:: Enum.__dir__(self)
|
||||
|
||||
Returns ``['__class__', '__doc__', '__module__', 'name', 'value']`` and
|
||||
any public methods defined on *self.__class__*::
|
||||
any public methods defined on ``self.__class__`` or a mixin class::
|
||||
|
||||
>>> from datetime import date
|
||||
>>> class Weekday(Enum):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue