mirror of
https://github.com/python/cpython.git
synced 2024-11-23 09:54:58 +08:00
Issue 18693: Put custom __dir__ back in place. Will instead look at fixing help()
.
This commit is contained in:
parent
8f2c2bcc9d
commit
388a3921cf
@ -223,6 +223,9 @@ class EnumMeta(type):
|
||||
def __contains__(cls, member):
|
||||
return isinstance(member, cls) and member.name in cls._member_map_
|
||||
|
||||
def __dir__(self):
|
||||
return ['__class__', '__doc__', '__members__'] + self._member_names_
|
||||
|
||||
@property
|
||||
def __members__(cls):
|
||||
"""Returns a mapping of member name->value.
|
||||
@ -430,6 +433,9 @@ class Enum(metaclass=EnumMeta):
|
||||
def __str__(self):
|
||||
return "%s.%s" % (self.__class__.__name__, self._name_)
|
||||
|
||||
def __dir__(self):
|
||||
return (['__class__', '__doc__', 'name', 'value'])
|
||||
|
||||
def __eq__(self, other):
|
||||
if type(other) is self.__class__:
|
||||
return self is other
|
||||
|
@ -67,6 +67,21 @@ class TestEnum(unittest.TestCase):
|
||||
WINTER = 4
|
||||
self.Season = Season
|
||||
|
||||
def test_dir_on_class(self):
|
||||
Season = self.Season
|
||||
self.assertEqual(
|
||||
set(dir(Season)),
|
||||
set(['__class__', '__doc__', '__members__',
|
||||
'SPRING', 'SUMMER', 'AUTUMN', 'WINTER']),
|
||||
)
|
||||
|
||||
def test_dir_on_item(self):
|
||||
Season = self.Season
|
||||
self.assertEqual(
|
||||
set(dir(Season.WINTER)),
|
||||
set(['__class__', '__doc__', 'name', 'value']),
|
||||
)
|
||||
|
||||
def test_enum_in_enum_out(self):
|
||||
Season = self.Season
|
||||
self.assertIs(Season(Season.WINTER), Season.WINTER)
|
||||
|
Loading…
Reference in New Issue
Block a user