Skip to content

[docs] gh-101273: Expand enum documentation on limitations #101274

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 1 commit into from
Closed
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
20 changes: 20 additions & 0 deletions Doc/library/enum.rst
Original file line number Diff line number Diff line change
Expand Up @@ -925,3 +925,23 @@ Notes
>>> from enum import IntEnum
>>> class MyIntEnum(IntEnum):
... __str__ = IntEnum.__str__

Additionally, it's possible to end up shadowing a method or property from
a derived baseclass such as :meth:`str.title` or :attr:`~numbers.Rational.numerator`,
which can cause unexpected issues at runtime.

Consider the following examples::

>>> from enum import StrEnum
>>> class MyStrEnum(StrEnum):
... title = "RED"
>>> MyStrEnum.title.title()
Traceback (most recent call last):
...
TypeError: 'MyStrEnum' object is not callable

>>> from enum import IntEnum
>>> class MyIntEnum(IntEnum):
... numerator = 42
>>> MyIntEnum.numerator.numerator
<MyIntEnum.numerator: 42>