Skip to content

Commit

Permalink
pythongh-100690: [mock] hide ATTRIB_DENY_LIST and make it immutable
Browse files Browse the repository at this point in the history
  • Loading branch information
sobolevn committed Jan 7, 2023
1 parent 26ff436 commit 98c3166
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Lib/unittest/mock.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.")
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit 98c3166

Please sign in to comment.