summaryrefslogtreecommitdiffstats
path: root/Lib/enum.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2022-06-26 11:24:04 (GMT)
committerGitHub <noreply@github.com>2022-06-26 11:24:04 (GMT)
commit1b27ec5ac62606b6b5da34dfb794d5975949f864 (patch)
tree2c4af8fbc22c13479b3788d6d6eaec4c9f30a422 /Lib/enum.py
parent5ce819f3c50a30074c843d57c3488a911e4fa578 (diff)
downloadcpython-1b27ec5ac62606b6b5da34dfb794d5975949f864.zip
cpython-1b27ec5ac62606b6b5da34dfb794d5975949f864.tar.gz
cpython-1b27ec5ac62606b6b5da34dfb794d5975949f864.tar.bz2
[3.11] gh-93820: Pickle enum.Flag by name (GH-93891). (GH-94288)
(cherry picked from commit 536985814a7116f14c9bc90aa1b3e3d36d5b2367) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
Diffstat (limited to 'Lib/enum.py')
-rw-r--r--Lib/enum.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/Lib/enum.py b/Lib/enum.py
index 5bd4da9..e11093c 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -1286,7 +1286,21 @@ class Flag(Enum, boundary=STRICT):
"""
def __reduce_ex__(self, proto):
- return self.__class__, (self._value_, )
+ cls = self.__class__
+ unknown = self._value_ & ~cls._flag_mask_
+ member_value = self._value_ & cls._flag_mask_
+ if unknown and member_value:
+ return _or_, (cls(member_value), unknown)
+ for val in _iter_bits_lsb(member_value):
+ rest = member_value & ~val
+ if rest:
+ return _or_, (cls(rest), cls._value2member_map_.get(val))
+ else:
+ break
+ if self._name_ is None:
+ return cls, (self._value_,)
+ else:
+ return getattr, (cls, self._name_)
_numeric_repr_ = repr