mirror of
https://github.com/python/cpython.git
synced 2025-07-23 11:15:24 +00:00
gh-100690: [mock] hide ATTRIB_DENY_LIST
and make it immutable (#100819)
This commit is contained in:
parent
26ff43625e
commit
a109454e82
1 changed files with 6 additions and 2 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue