bpo-40084: Enum - dir() includes member attributes (GH-19219)
This commit is contained in:
parent
1b328ea9a7
commit
68526fe258
|
@ -644,7 +644,7 @@ class Enum(metaclass=EnumMeta):
|
||||||
for cls in self.__class__.mro()
|
for cls in self.__class__.mro()
|
||||||
for m in cls.__dict__
|
for m in cls.__dict__
|
||||||
if m[0] != '_' and m not in self._member_map_
|
if m[0] != '_' and m not in self._member_map_
|
||||||
]
|
] + [m for m in self.__dict__ if m[0] != '_']
|
||||||
return (['__class__', '__doc__', '__module__'] + added_behavior)
|
return (['__class__', '__doc__', '__module__'] + added_behavior)
|
||||||
|
|
||||||
def __format__(self, format_spec):
|
def __format__(self, format_spec):
|
||||||
|
|
|
@ -216,6 +216,18 @@ class TestEnum(unittest.TestCase):
|
||||||
set(['__class__', '__doc__', '__module__', 'name', 'value', 'invisible']),
|
set(['__class__', '__doc__', '__module__', 'name', 'value', 'invisible']),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def test_dir_on_sub_with_behavior_including_instance_dict_on_super(self):
|
||||||
|
# see issue40084
|
||||||
|
class SuperEnum(IntEnum):
|
||||||
|
def __new__(cls, value, description=""):
|
||||||
|
obj = int.__new__(cls, value)
|
||||||
|
obj._value_ = value
|
||||||
|
obj.description = description
|
||||||
|
return obj
|
||||||
|
class SubEnum(SuperEnum):
|
||||||
|
sample = 5
|
||||||
|
self.assertTrue({'description'} <= set(dir(SubEnum.sample)))
|
||||||
|
|
||||||
def test_enum_in_enum_out(self):
|
def test_enum_in_enum_out(self):
|
||||||
Season = self.Season
|
Season = self.Season
|
||||||
self.assertIs(Season(Season.WINTER), Season.WINTER)
|
self.assertIs(Season(Season.WINTER), Season.WINTER)
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import errno
|
import errno
|
||||||
from http import client
|
from http import client, HTTPStatus
|
||||||
import io
|
import io
|
||||||
import itertools
|
import itertools
|
||||||
import os
|
import os
|
||||||
|
@ -519,6 +519,10 @@ class TransferEncodingTest(TestCase):
|
||||||
|
|
||||||
|
|
||||||
class BasicTest(TestCase):
|
class BasicTest(TestCase):
|
||||||
|
def test_dir_with_added_behavior_on_status(self):
|
||||||
|
# see issue40084
|
||||||
|
self.assertTrue({'description', 'name', 'phrase', 'value'} <= set(dir(HTTPStatus(404))))
|
||||||
|
|
||||||
def test_status_lines(self):
|
def test_status_lines(self):
|
||||||
# Test HTTP status lines
|
# Test HTTP status lines
|
||||||
|
|
||||||
|
|
|
@ -191,6 +191,7 @@ Gawain Bolton
|
||||||
Carl Friedrich Bolz-Tereick
|
Carl Friedrich Bolz-Tereick
|
||||||
Forest Bond
|
Forest Bond
|
||||||
Gregory Bond
|
Gregory Bond
|
||||||
|
Angelin Booz
|
||||||
Médéric Boquien
|
Médéric Boquien
|
||||||
Matias Bordese
|
Matias Bordese
|
||||||
Jonas Borgström
|
Jonas Borgström
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Fix ``Enum.__dir__``: dir(Enum.member) now includes attributes as well as methods.
|
Loading…
Reference in New Issue