summaryrefslogtreecommitdiffstats
path: root/Lib/unittest
diff options
context:
space:
mode:
authorNikita Sobolev <mail@sobolevn.me>2023-01-07 10:25:05 (GMT)
committerGitHub <noreply@github.com>2023-01-07 10:25:05 (GMT)
commita109454e828ce2d9bde15dea78405f8ffee653ec (patch)
tree470293f4b1aa36033cf9fcc50ea4061fe802b34c /Lib/unittest
parent26ff43625ed7bf09542ad8f149cb6af710b41e15 (diff)
downloadcpython-a109454e828ce2d9bde15dea78405f8ffee653ec.zip
cpython-a109454e828ce2d9bde15dea78405f8ffee653ec.tar.gz
cpython-a109454e828ce2d9bde15dea78405f8ffee653ec.tar.bz2
gh-100690: [mock] hide `ATTRIB_DENY_LIST` and make it immutable (#100819)
Diffstat (limited to 'Lib/unittest')
-rw-r--r--Lib/unittest/mock.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index 78827d6..b3c0e28 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -653,7 +653,7 @@ class NonCallableMock(Base):
elif _is_magic(name):
raise AttributeError(name)
if not self._mock_unsafe and (not self._mock_methods or name not in self._mock_methods):
- if name.startswith(('assert', 'assret', 'asert', 'aseert', 'assrt')) or name in ATTRIB_DENY_LIST:
+ if name.startswith(('assert', 'assret', 'asert', 'aseert', 'assrt')) or name in _ATTRIB_DENY_LIST:
raise AttributeError(
f"{name!r} is not a valid assertion. Use a spec "
f"for the mock if {name!r} is meant to be an attribute.")
@@ -1063,7 +1063,11 @@ class NonCallableMock(Base):
# Denylist for forbidden attribute names in safe mode
-ATTRIB_DENY_LIST = {name.removeprefix("assert_") for name in dir(NonCallableMock) if name.startswith("assert_")}
+_ATTRIB_DENY_LIST = frozenset({
+ name.removeprefix("assert_")
+ for name in dir(NonCallableMock)
+ if name.startswith("assert_")
+})
class _AnyComparer(list):