diff options
author | Petr Viktorin <encukou@gmail.com> | 2024-12-20 19:40:58 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-12-20 19:40:58 (GMT) |
commit | 2a66dd33dfc0b845042da9bb54aaa4e890733f54 (patch) | |
tree | f1d64ee79cc6f670d53e8160128521d7007cebed /Doc/library | |
parent | 3879ca0100942ae15a09ac22889cbe3e46d424eb (diff) | |
download | cpython-2a66dd33dfc0b845042da9bb54aaa4e890733f54.zip cpython-2a66dd33dfc0b845042da9bb54aaa4e890733f54.tar.gz cpython-2a66dd33dfc0b845042da9bb54aaa4e890733f54.tar.bz2 |
gh-112328: Make EnumDict usable on its own and document it (GH-123669)
Co-authored-by: Rafi <rafi.promit@gmail.com>
Co-authored-by: Sviatoslav Sydorenko (Святослав Сидоренко) <wk.cvs.github@sydorenko.org.ua>
Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
Diffstat (limited to 'Doc/library')
-rw-r--r-- | Doc/library/enum.rst | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/Doc/library/enum.rst b/Doc/library/enum.rst index 51292a1..8ca9493 100644 --- a/Doc/library/enum.rst +++ b/Doc/library/enum.rst @@ -110,6 +110,10 @@ Module Contents ``KEEP`` which allows for more fine-grained control over how invalid values are dealt with in an enumeration. + :class:`EnumDict` + + A subclass of :class:`dict` for use when subclassing :class:`EnumType`. + :class:`auto` Instances are replaced with an appropriate value for Enum members. @@ -149,14 +153,10 @@ Module Contents Return a list of all power-of-two integers contained in a flag. - :class:`EnumDict` - - A subclass of :class:`dict` for use when subclassing :class:`EnumType`. - .. versionadded:: 3.6 ``Flag``, ``IntFlag``, ``auto`` .. versionadded:: 3.11 ``StrEnum``, ``EnumCheck``, ``ReprEnum``, ``FlagBoundary``, ``property``, ``member``, ``nonmember``, ``global_enum``, ``show_flag_values`` -.. versionadded:: 3.14 ``EnumDict`` +.. versionadded:: 3.13 ``EnumDict`` --------------- @@ -830,13 +830,23 @@ Data Types .. class:: EnumDict - *EnumDict* is a subclass of :class:`dict` for use when subclassing :class:`EnumType`. + *EnumDict* is a subclass of :class:`dict` that is used as the namespace + for defining enum classes (see :ref:`prepare`). + It is exposed to allow subclasses of :class:`EnumType` with advanced + behavior like having multiple values per member. + It should be called with the name of the enum class being created, otherwise + private names and internal classes will not be handled correctly. + + Note that only the :class:`~collections.abc.MutableMapping` interface + (:meth:`~object.__setitem__` and :meth:`~dict.update`) is overridden. + It may be possible to bypass the checks using other :class:`!dict` + operations like :meth:`|= <object.__ior__>`. .. attribute:: EnumDict.member_names - Return list of member names. + A list of member names. - .. versionadded:: 3.14 + .. versionadded:: 3.13 --------------- |