[Python-checkins] gh-100690: [mock] hide `ATTRIB_DENY_LIST` and make it immutable (#100819)
cjw296
webhook-mailer at python.org
Sat Jan 7 05:25:34 EST 2023
https://github.com/python/cpython/commit/a109454e828ce2d9bde15dea78405f8ffee653ec
commit: a109454e828ce2d9bde15dea78405f8ffee653ec
branch: main
author: Nikita Sobolev <mail at sobolevn.me>
committer: cjw296 <chris at withers.org>
date: 2023-01-07T10:25:05Z
summary:
gh-100690: [mock] hide `ATTRIB_DENY_LIST` and make it immutable (#100819)
files:
M Lib/unittest/mock.py
diff --git a/Lib/unittest/mock.py b/Lib/unittest/mock.py
index 78827d61b69d..b3c0e28c698b 100644
--- a/Lib/unittest/mock.py
+++ b/Lib/unittest/mock.py
@@ -653,7 +653,7 @@ def __getattr__(self, name):
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 @@ def _calls_repr(self, prefix="Calls"):
# 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):
More information about the Python-checkins
mailing list