Skip to content

Commit afde363

Browse files
committed
Expand enum documentation to include additional limitations when shadowing a built-in
1 parent bd79039 commit afde363

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

Doc/library/enum.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,3 +925,23 @@ Notes
925925
>>> from enum import IntEnum
926926
>>> class MyIntEnum(IntEnum):
927927
... __str__ = IntEnum.__str__
928+
929+
Additionally, it's possible to end up shadowing a method or property from
930+
a derived baseclass such as :meth:`str.title` or :attr:`~numbers.Rational.numerator`,
931+
which can cause unexpected issues at runtime.
932+
933+
Consider the following examples::
934+
935+
>>> from enum import StrEnum
936+
>>> class MyStrEnum(StrEnum):
937+
... title = "RED"
938+
>>> MyStrEnum.title.title()
939+
Traceback (most recent call last):
940+
...
941+
TypeError: 'MyStrEnum' object is not callable
942+
943+
>>> from enum import IntEnum
944+
>>> class MyIntEnum(IntEnum):
945+
... numerator = 42
946+
>>> MyIntEnum.numerator.numerator
947+
<MyIntEnum.numerator: 42>

0 commit comments

Comments
 (0)