Issue22506: merge from 3.4

This commit is contained in:
Ethan Furman 2014-10-14 08:59:14 -07:00
commit 987f3dd161
2 changed files with 18 additions and 1 deletions

View File

@ -464,7 +464,12 @@ class Enum(metaclass=EnumMeta):
return "%s.%s" % (self.__class__.__name__, self._name_)
def __dir__(self):
added_behavior = [m for m in self.__class__.__dict__ if m[0] != '_']
added_behavior = [
m
for cls in self.__class__.mro()
for m in cls.__dict__
if m[0] != '_'
]
return (['__class__', '__doc__', '__module__', 'name', 'value'] +
added_behavior)

View File

@ -176,6 +176,18 @@ class TestEnum(unittest.TestCase):
set(['__class__', '__doc__', '__module__', 'name', 'value', 'wowser']),
)
def test_dir_on_sub_with_behavior_on_super(self):
# see issue22506
class SuperEnum(Enum):
def invisible(self):
return "did you see me?"
class SubEnum(SuperEnum):
sample = 5
self.assertEqual(
set(dir(SubEnum.sample)),
set(['__class__', '__doc__', '__module__', 'name', 'value', 'invisible']),
)
def test_enum_in_enum_out(self):
Season = self.Season
self.assertIs(Season(Season.WINTER), Season.WINTER)