Kaydet (Commit) 6db1fd5f authored tarafından Ethan Furman's avatar Ethan Furman

Close issue24840: Enum._value_ is queried for bool(); original patch by Mike Lundy

üst b1a3d9ae
......@@ -476,6 +476,9 @@ class Enum(metaclass=EnumMeta):
def __str__(self):
return "%s.%s" % (self.__class__.__name__, self._name_)
def __bool__(self):
return bool(self._value_)
def __dir__(self):
added_behavior = [
m
......
......@@ -270,6 +270,13 @@ class TestEnum(unittest.TestCase):
class Wrong(Enum):
_any_name_ = 9
def test_bool(self):
class Logic(Enum):
true = True
false = False
self.assertTrue(Logic.true)
self.assertFalse(Logic.false)
def test_contains(self):
Season = self.Season
self.assertIn(Season.AUTUMN, Season)
......
......@@ -877,6 +877,7 @@ Kang-Hao (Kenny) Lu
Lukas Lueg
Loren Luke
Fredrik Lundh
Mike Lundy
Zhongyue Luo
Mark Lutz
Taras Lyapun
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment