aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/Lib/enum.py
diff options
context:
space:
mode:
authorEthan Furman <ethan@stoneleaf.us>2020-09-16 13:01:00 -0700
committerGitHub <noreply@github.com>2020-09-16 13:01:00 -0700
commit7219e27087baaa8a5693b5bef1b1357bddbffa53 (patch)
tree9235d51826e2a14c26220a63a536085615604d16 /Lib/enum.py
parentfc23a9483ef0d7c98bea9f82392377d0b6ef7b18 (diff)
downloadcpython-7219e27087baaa8a5693b5bef1b1357bddbffa53.tar.gz
cpython-7219e27087baaa8a5693b5bef1b1357bddbffa53.zip
Enum: make `Flag` and `IntFlag` members iterable (GH-22221)
Diffstat (limited to 'Lib/enum.py')
-rw-r--r--Lib/enum.py4
1 files changed, 4 insertions, 0 deletions
diff --git a/Lib/enum.py b/Lib/enum.py
index 21a94caaee3..3c459ea4113 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -753,6 +753,10 @@ class Flag(Enum):
type(other).__qualname__, self.__class__.__qualname__))
return other._value_ & self._value_ == other._value_
+ def __iter__(self):
+ members, extra_flags = _decompose(self.__class__, self.value)
+ return (m for m in members if m._value_ != 0)
+
def __repr__(self):
cls = self.__class__
if self._name_ is not None: