Skip to content

Commit 2719ecb

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

File tree

2 files changed

+15
-0
lines changed

2 files changed

+15
-0
lines changed

Doc/library/enum.rst

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -925,3 +925,17 @@ 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 built-in functions from
930+
the derived baseclass such as :meth:`str.title` or :meth:`int.bit_count`,
931+
which can cause unexpected issues at runtime.
932+
933+
Consider the following example::
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
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Expand :mod:`enum` documentation on limitations when shadowing a built-in.

0 commit comments

Comments
 (0)