FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

[docs] gh-101273: Expand enum documentation on limitations by samypr100 · Pull Request #101274 · python/cpython · GitHub

/ cpython Public
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .rst  (1) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
20 changes: 20 additions & 0 deletions Doc/library/enum.rst
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
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()
Comment thread
samypr100 marked this conversation as resolved.
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>

Back | FazBrowse Home | New Git URL