8000 bpo-45331: [Enum] add rule to docs that mixin type must be subclassab… · python/cpython@6223cbf · GitHub
[go: up one dir, main page]

Skip to content

Commit 6223cbf

Browse files
authored
bpo-45331: [Enum] add rule to docs that mixin type must be subclassable (GH-30521)
1 parent 13e4659 commit 6223cbf

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

Doc/howto/enum.rst

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -819,17 +819,20 @@ Some rules:
819819
1. When subclassing :class:`Enum`, mix-in types must appear before
820820
:class:`Enum` itself in the sequence of bases, as in the :class:`IntEnum`
821821
example above.
822-
2. While :class:`Enum` can have members of any type, once you mix in an
822+
2. Mix-in types must be subclassable. For example,
823+
:class:`bool` and :class:`range` are not subclassable
824+
and will throw an error during Enum creation if used as the mix-in type.
825+
3. While :class:`Enum` can have members of any type, once you mix in an
823826
additional type, all the members must have values of that type, e.g.
824827
:class:`int` above. This restriction does not apply to mix-ins which only
825828
add methods and don't specify another type.
826-
3. When another data type is mixed in, the :attr:`value` attribute is *not the
829+
4. When another data type is mixed in, the :attr:`value` attribute is *not the
827830
same* as the enum member itself, although it is equivalent and will compare
828831
equal.
829-
4. %-style formatting: `%s` and `%r` call the :class:`Enum` class's
832+
5. %-style formatting: `%s` and `%r` call the :class:`Enum` class's
830833
:meth:`__str__` and :meth:`__repr__` respectively; other codes (such as
831834
`%i` or `%h` for IntEnum) treat the enum member as its mixed-in type.
832-
5. :ref:`Formatted string literals <f-strings>`, :meth:`str.format`,
835+
6. :ref:`Formatted string literals <f-strings>`, :meth:`str.format`,
833836
and :func:`format` will use the mixed-in type's :meth:`__format__`
834837
unless :meth:`__str__` or :meth:`__format__` is overridden in the subclass,
835838
in which case the overridden methods or :class:`Enum` methods will be used.

0 commit comments

Comments
 (0)
0