summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-10-31 22:01:28 (GMT)
committerGitHub <noreply@github.com>2023-10-31 22:01:28 (GMT)
commitec00397912ea57a896cb7029e14fad89371b8b2f (patch)
tree2f0efa07d2acab3f0abb328cbd8fc67cfa91933c /Lib
parent4f619e83fe1416c9b8d618533a0aaec0b4443b11 (diff)
downloadcpython-ec00397912ea57a896cb7029e14fad89371b8b2f.zip
cpython-ec00397912ea57a896cb7029e14fad89371b8b2f.tar.gz
cpython-ec00397912ea57a896cb7029e14fad89371b8b2f.tar.bz2
[3.12] gh-111181: Fix enum doctests (GH-111180) (GH-111518)
gh-111181: Fix enum doctests (GH-111180) (cherry picked from commit c4dc5a6ae8aa13abb743182df088f1a3526d1bcd) Co-authored-by: Nikita Sobolev <mail@sobolevn.me> Co-authored-by: Ethan Furman <ethan@stoneleaf.us>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/enum.py11
-rw-r--r--Lib/test/test_enum.py17
2 files changed, 16 insertions, 12 deletions
diff --git a/Lib/enum.py b/Lib/enum.py
index c207dc2..4bd3756 100644
--- a/Lib/enum.py
+++ b/Lib/enum.py
@@ -1217,14 +1217,13 @@ class Enum(metaclass=EnumType):
def __dir__(self):
"""
- Returns all members and all public methods
+ Returns public methods and other interesting attributes.
"""
- if self.__class__._member_type_ is object:
- interesting = set(['__class__', '__doc__', '__eq__', '__hash__', '__module__', 'name', 'value'])
- else:
+ interesting = set()
+ if self.__class__._member_type_ is not object:
interesting = set(object.__dir__(self))
for name in getattr(self, '__dict__', []):
- if name[0] != '_':
+ if name[0] != '_' and name not in self._member_map_:
interesting.add(name)
for cls in self.__class__.mro():
for name, obj in cls.__dict__.items():
@@ -1237,7 +1236,7 @@ class Enum(metaclass=EnumType):
else:
# in case it was added by `dir(self)`
interesting.discard(name)
- else:
+ elif name not in self._member_map_:
interesting.add(name)
names = sorted(
set(['__class__', '__doc__', '__eq__', '__hash__', '__module__'])
diff --git a/Lib/test/test_enum.py b/Lib/test/test_enum.py
index 14f16f7..3bd918f 100644
--- a/Lib/test/test_enum.py
+++ b/Lib/test/test_enum.py
@@ -18,7 +18,7 @@ from enum import member, nonmember, _iter_bits_lsb
from io import StringIO
from pickle import dumps, loads, PicklingError, HIGHEST_PROTOCOL
from test import support
-from test.support import ALWAYS_EQ
+from test.support import ALWAYS_EQ, REPO_ROOT
from test.support import threading_helper
from datetime import timedelta
@@ -26,14 +26,19 @@ python_version = sys.version_info[:2]
def load_tests(loader, tests, ignore):
tests.addTests(doctest.DocTestSuite(enum))
- if os.path.exists('Doc/library/enum.rst'):
+
+ lib_tests = os.path.join(REPO_ROOT, 'Doc/library/enum.rst')
+ if os.path.exists(lib_tests):
tests.addTests(doctest.DocFileSuite(
- '../../Doc/library/enum.rst',
+ lib_tests,
+ module_relative=False,
optionflags=doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE,
))
- if os.path.exists('Doc/howto/enum.rst'):
+ howto_tests = os.path.join(REPO_ROOT, 'Doc/howto/enum.rst')
+ if os.path.exists(howto_tests):
tests.addTests(doctest.DocFileSuite(
- '../../Doc/howto/enum.rst',
+ howto_tests,
+ module_relative=False,
optionflags=doctest.ELLIPSIS|doctest.NORMALIZE_WHITESPACE,
))
return tests
@@ -5127,7 +5132,7 @@ def member_dir(member):
allowed.add(name)
else:
allowed.discard(name)
- else:
+ elif name not in member._member_map_:
allowed.add(name)
return sorted(allowed)