summaryrefslogtreecommitdiffstats
path: root/Doc/library/enum.rst
diff options
context:
space:
mode:
authorthatneat <thatneat@users.noreply.github.com>2019-07-04 18:28:37 (GMT)
committerEthan Furman <ethan@stoneleaf.us>2019-07-04 18:28:37 (GMT)
commit2f19e82fbe98ce86bcd98a176328af2808b678e8 (patch)
tree0febe00f3456e58aa82575a2c16a62f3e2385c6a /Doc/library/enum.rst
parentb4e68960b90627422325fdb75f463df1e4153c6e (diff)
downloadcpython-2f19e82fbe98ce86bcd98a176328af2808b678e8.zip
cpython-2f19e82fbe98ce86bcd98a176328af2808b678e8.tar.gz
cpython-2f19e82fbe98ce86bcd98a176328af2808b678e8.tar.bz2
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/library/enum.rst')
-rw-r--r--Doc/library/enum.rst8
1 files changed, 5 insertions, 3 deletions
diff --git a/Doc/library/enum.rst b/Doc/library/enum.rst
index 19277d7..d7d319a 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__`
------------------------------------------------