Skip to content

Commit a109454

Browse files
authored
gh-100690: [mock] hide ATTRIB_DENY_LIST and make it immutable (#100819)
1 parent 26ff436 commit a109454

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Lib/unittest/mock.py

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

10641064

10651065
# Denylist for forbidden attribute names in safe mode
1066-
ATTRIB_DENY_LIST = {name.removeprefix("assert_") for name in dir(NonCallableMock) if name.startswith("assert_")}
1066+
_ATTRIB_DENY_LIST = frozenset({
1067+
name.removeprefix("assert_")
1068+
for name in dir(NonCallableMock)
1069+
if name.startswith("assert_")
1070+
})
10671071

10681072

10691073
class _AnyComparer(list):

0 commit comments

Comments
 (0)