mirror of
https://github.com/python/cpython.git
synced 2025-09-20 07:31:10 +00:00
Close issue24840: Enum._value_ is queried for bool(); original patch by Mike Lundy
This commit is contained in:
parent
b1a3d9ae56
commit
6db1fd5fb8
3 changed files with 11 additions and 0 deletions
|
@ -476,6 +476,9 @@ class Enum(metaclass=EnumMeta):
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return "%s.%s" % (self.__class__.__name__, self._name_)
|
return "%s.%s" % (self.__class__.__name__, self._name_)
|
||||||
|
|
||||||
|
def __bool__(self):
|
||||||
|
return bool(self._value_)
|
||||||
|
|
||||||
def __dir__(self):
|
def __dir__(self):
|
||||||
added_behavior = [
|
added_behavior = [
|
||||||
m
|
m
|
||||||
|
|
|
@ -270,6 +270,13 @@ class TestEnum(unittest.TestCase):
|
||||||
class Wrong(Enum):
|
class Wrong(Enum):
|
||||||
_any_name_ = 9
|
_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):
|
def test_contains(self):
|
||||||
Season = self.Season
|
Season = self.Season
|
||||||
self.assertIn(Season.AUTUMN, Season)
|
self.assertIn(Season.AUTUMN, Season)
|
||||||
|
|
|
@ -877,6 +877,7 @@ Kang-Hao (Kenny) Lu
|
||||||
Lukas Lueg
|
Lukas Lueg
|
||||||
Loren Luke
|
Loren Luke
|
||||||
Fredrik Lundh
|
Fredrik Lundh
|
||||||
|
Mike Lundy
|
||||||
Zhongyue Luo
|
Zhongyue Luo
|
||||||
Mark Lutz
|
Mark Lutz
|
||||||
Taras Lyapun
|
Taras Lyapun
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue