diff options
author | Angelin BOOZ <9497359+lem2clide@users.noreply.github.com> | 2020-09-21 15:11:06 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-09-21 06:11:06 -0700 |
commit | 68526fe258da8c01196fd7cf48e8e5f1280bf8fd (patch) | |
tree | 45b3930335dca97d5b613100e12b0feaa7e218ed | |
parent | bpo-1635741: Convert an _lsprof method to argument clinic (GH-22240) (diff) | |
download | cpython-68526fe258da8c01196fd7cf48e8e5f1280bf8fd.tar.gz cpython-68526fe258da8c01196fd7cf48e8e5f1280bf8fd.tar.bz2 cpython-68526fe258da8c01196fd7cf48e8e5f1280bf8fd.zip |
bpo-40084: Enum - dir() includes member attributes (GH-19219)
-rw-r--r-- | Lib/enum.py | 2 | ||||
-rw-r--r-- | Lib/test/test_enum.py | 12 | ||||
-rw-r--r-- | Lib/test/test_httplib.py | 6 | ||||
-rw-r--r-- | Misc/ACKS | 1 | ||||
-rw-r--r-- | Misc/NEWS.d/next/Library/2020-03-29-21-32-00.bpo-40084.MCYwcv.rst | 1 |
5 files changed, 20 insertions, 2 deletions
diff --git a/Lib/enum.py b/Lib/enum.py index 3c459ea4113..e8603a43420 100644 --- a/Lib/enum.py +++ b/Lib/enum.py @@ -644,7 +644,7 @@ class Enum(metaclass=EnumMeta): for cls in self.__class__.mro() for m in cls.__dict__ 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) def __format__(self, format_spec): diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py index 59789fb7bcc..3f39073f5d5 100644 --- a/Lib/test/test_enum.py +++ b/Lib/test/test_enum.py @@ -216,6 +216,18 @@ class TestEnum(unittest.TestCase): 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): Season = self.Season self.assertIs(Season(Season.WINTER), Season.WINTER) diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py index a3f268be979..4abff60230b 100644 --- a/Lib/test/test_httplib.py +++ b/Lib/test/test_httplib.py @@ -1,5 +1,5 @@ import errno -from http import client +from http import client, HTTPStatus import io import itertools import os @@ -519,6 +519,10 @@ class TransferEncodingTest(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): # Test HTTP status lines diff --git a/Misc/ACKS b/Misc/ACKS index d23797a2f55..01ee1cb42d3 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -191,6 +191,7 @@ Gawain Bolton Carl Friedrich Bolz-Tereick Forest Bond Gregory Bond +Angelin Booz Médéric Boquien Matias Bordese Jonas Borgström diff --git a/Misc/NEWS.d/next/Library/2020-03-29-21-32-00.bpo-40084.MCYwcv.rst b/Misc/NEWS.d/next/Library/2020-03-29-21-32-00.bpo-40084.MCYwcv.rst new file mode 100644 index 00000000000..65ff4ce36e8 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2020-03-29-21-32-00.bpo-40084.MCYwcv.rst @@ -0,0 +1 @@ +Fix ``Enum.__dir__``: dir(Enum.member) now includes attributes as well as methods. |