mirror of
https://github.com/python/cpython.git
synced 2025-08-01 23:53:15 +00:00
branch merge
This commit is contained in:
commit
ccf44b0445
3 changed files with 26 additions and 5 deletions
|
@ -482,9 +482,6 @@ 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
|
||||
|
|
|
@ -272,11 +272,26 @@ class TestEnum(unittest.TestCase):
|
|||
_any_name_ = 9
|
||||
|
||||
def test_bool(self):
|
||||
# plain Enum members are always True
|
||||
class Logic(Enum):
|
||||
true = True
|
||||
false = False
|
||||
self.assertTrue(Logic.true)
|
||||
self.assertFalse(Logic.false)
|
||||
self.assertTrue(Logic.false)
|
||||
# unless overridden
|
||||
class RealLogic(Enum):
|
||||
true = True
|
||||
false = False
|
||||
def __bool__(self):
|
||||
return bool(self._value_)
|
||||
self.assertTrue(RealLogic.true)
|
||||
self.assertFalse(RealLogic.false)
|
||||
# mixed Enums depend on mixed-in type
|
||||
class IntLogic(int, Enum):
|
||||
true = 1
|
||||
false = 0
|
||||
self.assertTrue(IntLogic.true)
|
||||
self.assertFalse(IntLogic.false)
|
||||
|
||||
def test_contains(self):
|
||||
Season = self.Season
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue