MCPcopy Index your code
hub / github.com/RustPython/RustPython / __getattr__

Method __getattr__

Lib/unittest/mock.py:691–736  ·  view source on GitHub ↗
(self, name)

Source from the content-addressed store, hash-verified

689
690
691 def __getattr__(self, name):
692 if name in {'_mock_methods', '_mock_unsafe'}:
693 raise AttributeError(name)
694 elif self._mock_methods is not None:
695 if name not in self._mock_methods or name in _all_magics:
696 raise AttributeError("Mock object has no attribute %r" % name)
697 elif _is_magic(name):
698 raise AttributeError(name)
699 if not self._mock_unsafe and (not self._mock_methods or name not in self._mock_methods):
700 if name.startswith(('assert', 'assret', 'asert', 'aseert', 'assrt')) or name in _ATTRIB_DENY_LIST:
701 raise AttributeError(
702 f"{name!r} is not a valid assertion. Use a spec "
703 f"for the mock if {name!r} is meant to be an attribute.")
704
705 with NonCallableMock._lock:
706 result = self._mock_children.get(name)
707 if result is _deleted:
708 raise AttributeError(name)
709 elif result is None:
710 wraps = None
711 if self._mock_wraps is not None:
712 # XXXX should we get the attribute without triggering code
713 # execution?
714 wraps = getattr(self._mock_wraps, name)
715
716 result = self._get_child_mock(
717 parent=self, name=name, wraps=wraps, _new_name=name,
718 _new_parent=self
719 )
720 self._mock_children[name] = result
721
722 elif isinstance(result, _SpecState):
723 try:
724 result = create_autospec(
725 result.spec, result.spec_set, result.instance,
726 result.parent, result.name
727 )
728 except InvalidSpecError:
729 target_name = self.__dict__['_mock_name'] or self
730 raise InvalidSpecError(
731 f'Cannot autospec attr {name!r} from target '
732 f'{target_name!r} as it has already been mocked out. '
733 f'[target={self!r}, attr={result.spec!r}]')
734 self._mock_children[name] = result
735
736 return result
737
738
739 def _extract_mock_name(self):

Callers

nothing calls this directly

Calls 8

_get_child_mockMethod · 0.95
_is_magicFunction · 0.85
getattrFunction · 0.85
isinstanceFunction · 0.85
create_autospecFunction · 0.85
InvalidSpecErrorClass · 0.85
startswithMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected