Skip to content

Commit 18046f1

Browse files
sobolevncjw296
authored andcommitted
gh-100690: [mock] hide ATTRIB_DENY_LIST and make it immutable (#100819)
Backports: a109454e828ce2d9bde15dea78405f8ffee653ec Signed-off-by: Chris Withers <chris@simplistix.co.uk>
1 parent 21787a9 commit 18046f1

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

mock/mock.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -656,7 +656,7 @@ def __getattr__(self, name):
656656
elif _is_magic(name):
657657
raise AttributeError(name)
658658
if not self._mock_unsafe and (not self._mock_methods or name not in self._mock_methods):
659-
if name.startswith(('assert', 'assret', 'asert', 'aseert', 'assrt')) or name in ATTRIB_DENY_LIST:
659+
if name.startswith(('assert', 'assret', 'asert', 'aseert', 'assrt')) or name in _ATTRIB_DENY_LIST:
660660
raise AttributeError(
661661
f"{name!r} is not a valid assertion. Use a spec "
662662
f"for the mock if {name!r} is meant to be an attribute.")
@@ -1071,7 +1071,11 @@ def _calls_repr(self, prefix="Calls"):
10711071

10721072

10731073
# Denylist for forbidden attribute names in safe mode
1074-
ATTRIB_DENY_LIST = {name.removeprefix("assert_") for name in dir(NonCallableMock) if name.startswith("assert_")}
1074+
_ATTRIB_DENY_LIST = frozenset({
1075+
name.removeprefix("assert_")
1076+
for name in dir(NonCallableMock)
1077+
if name.startswith("assert_")
1078+
})
10751079

10761080

10771081
class _AnyComparer(list):

0 commit comments

Comments
 (0)