@@ -632,48 +632,74 @@ datetime
632
632
formats (barring only those that support fractional hours and minutes).
633
633
(Contributed by Paul Ganssle in :gh: `80010 `.)
634
634
635
- enum
636
- ----
637
-
638
- * ``EnumMeta `` renamed to ``EnumType `` (``EnumMeta `` kept as alias).
639
-
640
- * ``StrEnum `` added -- enum members are and must be strings.
641
-
642
- * ``ReprEnum `` added -- causes only the ``__repr__ `` to be modified, not the
643
- ``__str__ `` nor the ``__format__ ``.
644
-
645
- * ``FlagBoundary `` added -- controls behavior when invalid values are given to
646
- a flag.
647
-
648
- * ``EnumCheck `` added -- used by ``verify `` to ensure various constraints.
649
635
650
- * `` verify `` added -- function to ensure given `` EnumCheck `` constraints.
636
+ .. _ whatsnew311-enum :
651
637
652
- * ``member `` added -- decorator to ensure given object is converted to an enum
653
- member.
654
-
655
- * ``nonmember `` added -- decorator to ensure given object is not converted to
656
- an enum member.
657
-
658
- * ``property `` added -- use instead of ``types.DynamicClassAttribute ``.
659
-
660
- * ``global_enum `` added -- enum decorator to adjust ``__repr__ `` and ``__str__ ``
661
- to show members in the global context -- see ``re.RegexFlag `` for an example.
662
-
663
- * ``Flag `` enhancements: members support length, iteration, and containment
664
- checks.
665
-
666
- * ``Enum ``/``Flag `` fixes: members are now defined before ``__init_subclass__ ``
667
- is called; ``dir() `` now includes methods, etc., from mixed-in data types.
638
+ enum
639
+ ----
668
640
669
- * ``Flag `` fixes: only primary values (power of two) are considered canonical
670
- while composite values (3, 6, 10, etc.) are considered aliases; inverted
671
- flags are coerced to their positive equivalent.
641
+ * Renamed :class: `!EnumMeta ` to :class: `~enum.EnumType `
642
+ (:class: `!EnumMeta ` kept as an alias).
643
+
644
+ * Added :class: `~enum.StrEnum `,
645
+ with members that can be used as (and must be) strings.
646
+
647
+ * Added :class: `~enum.ReprEnum `,
648
+ which only modifies the :meth: `~object.__repr__ ` of members
649
+ while returning their literal values (rather than names)
650
+ for :meth: `~object.__str__ ` and :meth: `~object.__format__ `
651
+ (used by :func: `str `, :func: `format ` and :term: `f-string `\s ).
652
+
653
+ * Changed :class: `~enum.IntEnum `, :class: `~enum.IntFlag ` and :class: `~enum.StrEnum `
654
+ to now inherit from :class: `ReprEnum `,
655
+ so their :func: `str ` output now matches :func: `format `
656
+ (both ``str(AnIntEnum.ONE) `` and ``format(AnIntEnum.ONE) `` return ``'1' ``,
657
+ whereas before ``str(AnIntEnum.ONE) `` returned ``'AnIntEnum.ONE' ``.
658
+
659
+ * Changed :meth: `Enum.__format__() <enum.Enum.__format__> `
660
+ (the default for :func: `format `, :meth: `str.format ` and :term: `f-string `\s )
661
+ of enums with mixed-in types (e.g. :class: `int `, :class: `str `)
662
+ to also include the class name in the output, not just the member's key.
663
+ This matches the existing behavior of :meth: `enum.Enum.__str__ `,
664
+ returning e.g. ``'AnEnum.MEMBER' `` for an enum ``AnEnum(str, Enum) ``
665
+ instead of just ``'MEMBER' ``.
666
+
667
+ * Added a new *boundary * class parameter to :class: `~enum.Flag ` enums
668
+ and the :class: `~enum.FlagBoundary ` enum with its options,
669
+ to control how to handle out-of-range flag values.
670
+
671
+ * Added the :func: `~enum.verify ` enum decorator
672
+ and the :class: `~enum.EnumCheck ` enum with its options,
673
+ to check enum classes against several specific constraints.
674
+
675
+ * Added the :func: `~enum.member ` and :func: `~enum.nonmember ` decorators,
676
+ to ensure the decorated object is/is not converted to an enum member.
677
+
678
+ * Added the :func: `~enum.property ` decorator,
679
+ which works like :func: `property ` except for enums.
680
+ Use this instead of :func: `types.DynamicClassAttribute `.
681
+
682
+ * Added the :func: `~enum.global_enum ` enum decorator,
683
+ which adjusts :meth: `~object.__repr__ ` and :meth: `~object.__str__ `
684
+ to show values as members of their module rather than the enum class.
685
+ For example, ``'re.ASCII' `` for the :data: `~re.ASCII ` member
686
+ of :class: `re.RegexFlag ` rather than ``'RegexFlag.ASCII' ``.
687
+
688
+ * Enhanced :class: `~enum.Flag ` to support
689
+ :func: `len `, iteration and :keyword: `in `/:keyword: `not in ` on its members.
690
+ For example, the following now works:
691
+ ``len(AFlag(3)) == 2 and list(AFlag(3)) == (AFlag.ONE, AFlag.TWO) ``
692
+
693
+ * Changed :class: `~enum.Enum ` and :class: `~enum.Flag `
694
+ so that members are now defined
695
+ before :meth: `~object.__init_subclass__ ` is called;
696
+ :func: `dir ` now includes methods, etc., from mixed-in data types.
697
+
698
+ * Changed :class: `~enum.Flag `
699
+ to only consider primary values (power of two) canonical
700
+ while composite values (``3 ``, ``6 ``, ``10 ``, etc.) are considered aliases;
701
+ inverted flags are coerced to their positive equivalent.
672
702
673
- * ``IntEnum `` / ``IntFlag `` / ``StrEnum `` fixes: these now inherit from
674
- ``ReprEnum `` so the ``str() `` output now matches ``format() `` output,
675
- which is the data types' (so both ``str(AnIntEnum.ONE) `` and
676
- ``format(AnIntEnum.ONE) `` is equal to ``'1' ``).
677
703
678
704
fractions
679
705
---------
0 commit comments