diff options
author | 2019-07-04 11:28:37 -0700 | |
---|---|---|
committer | 2019-07-04 11:28:37 -0700 | |
commit | 2f19e82fbe98ce86bcd98a176328af2808b678e8 (patch) | |
tree | 0febe00f3456e58aa82575a2c16a62f3e2385c6a /Doc | |
parent | bpo-37266: Add bpo number to the What's New entry (GH614584) (diff) | |
download | cpython-2f19e82fbe98ce86bcd98a176328af2808b678e8.tar.gz cpython-2f19e82fbe98ce86bcd98a176328af2808b678e8.tar.bz2 cpython-2f19e82fbe98ce86bcd98a176328af2808b678e8.zip |
bpo-37479: on Enum subclasses with mixins, __format__ uses overridden __str__ (GH-14545)
* bpo-37479: on Enum subclasses with mixins, __format__ uses overridden __str__
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/enum.rst | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/Doc/library/enum.rst b/Doc/library/enum.rst index 19277d76995..d7d319a9513 100644 --- a/Doc/library/enum.rst +++ b/Doc/library/enum.rst @@ -739,9 +739,11 @@ Some rules: :meth:`__str__` and :meth:`__repr__` respectively; other codes (such as `%i` or `%h` for IntEnum) treat the enum member as its mixed-in type. 5. :ref:`Formatted string literals <f-strings>`, :meth:`str.format`, - and :func:`format` will use the mixed-in - type's :meth:`__format__`. If the :class:`Enum` class's :func:`str` or - :func:`repr` is desired, use the `!s` or `!r` format codes. + and :func:`format` will use the mixed-in type's :meth:`__format__` + unless :meth:`__str__` or :meth:`__format__` is overridden in the subclass, + in which case the overridden methods or :class:`Enum` methods will be used. + Use the !s and !r format codes to force usage of the :class:`Enum` class's + :meth:`__str__` and :meth:`__repr__` methods. When to use :meth:`__new__` vs. :meth:`__init__` ------------------------------------------------ |