gh-93820: Fix copy() regression in enum.Flag (GH-93876) (#93886)

GH-26658 introduced a regression in copy / pickle protocol for combined
`enum.Flag`s. `copy.copy(re.A | re.I)` would fail with
`AttributeError: ASCII|IGNORECASE`.

`enum.Flag` now has a `__reduce_ex__()` method that reduces flags by
combined value, not by combined name.
(cherry picked from commit 05b32c1c79)

Co-authored-by: Christian Heimes <christian@python.org>

Co-authored-by: Christian Heimes <christian@python.org>
This commit is contained in:
Miss Islington (bot) 2022-06-16 20:56:20 -07:00 committed by GitHub
parent 74561095d9
commit 3fbf5c6427
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 0 deletions

View file

@ -1372,6 +1372,9 @@ class Flag(Enum, boundary=STRICT):
Support for flags
"""
def __reduce_ex__(self, proto):
return self.__class__, (self._value_, )
_numeric_repr_ = repr
def _generate_next_value_(name, start, count, last_values):