]> granicus.if.org Git - python/commitdiff
Issue22506: added methods on base Enum class now show up in dir of Enum subclass...
authorEthan Furman <ethan@stoneleaf.us>
Tue, 14 Oct 2014 15:58:32 +0000 (08:58 -0700)
committerEthan Furman <ethan@stoneleaf.us>
Tue, 14 Oct 2014 15:58:32 +0000 (08:58 -0700)
Lib/enum.py
Lib/test/test_enum.py

index 84fa20e11091a7ea3e5d9a6160e8af29aefd91d8..9b19c1d34bd340f593c6ed17d85183185396852d 100644 (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)
 
index f1f80631eb5739b72cc9d70593cdd96a84a1277a..dccaa4ffaaf2f16060b7cb4b1e7077fbf7763dc9 100644 (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)