8000 [3.9] bpo-40084: Enum - dir() includes member attributes (GH-19219) by miss-islington · Pull Request #23746 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.9] bpo-40084: Enum - dir() includes member attributes (GH-19219) #23746

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 14, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Lib/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -699,7 +699,7 @@ def __dir__(self):
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):
Expand Down
12 changes: 12 additions & 0 deletions Lib/test/test_enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,18 @@ class SubEnum(SuperEnum):
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)
Expand Down
6 changes: 5 additions & 1 deletion Lib/test/test_httplib.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import errno
from http import client
from http import client, HTTPStatus
import io
import itertools
import os
Expand Down Expand Up @@ -516,6 +516,10 @@ def _parse_chunked(self, data):


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

Expand Down
1 change: 1 addition & 0 deletions Misc/ACKS
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ Gawain Bolton
Carl Friedrich Bolz-Tereick
Forest Bond
Gregory Bond
Angelin Booz
Médéric Boquien
Matias Bordese
Jonas Borgström
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix ``Enum.__dir__``: dir(Enum.member) now includes attributes as well as methods.
0