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

Method __setattr__

Lib/unittest/mock.py:805–844  ·  view source on GitHub ↗
(self, name, value)

Source from the content-addressed store, hash-verified

803
804
805 def __setattr__(self, name, value):
806 if name in _allowed_names:
807 # property setters go through here
808 return object.__setattr__(self, name, value)
809 elif (self._spec_set and self._mock_methods is not None and
810 name not in self._mock_methods and
811 name not in self.__dict__):
812 raise AttributeError("Mock object has no attribute '%s'" % name)
813 elif name in _unsupported_magics:
814 msg = 'Attempting to set unsupported magic method %r.' % name
815 raise AttributeError(msg)
816 elif name in _all_magics:
817 if self._mock_methods is not None and name not in self._mock_methods:
818 raise AttributeError("Mock object has no attribute '%s'" % name)
819
820 if not _is_instance_mock(value):
821 setattr(type(self), name, _get_method(name, value))
822 original = value
823 value = lambda *args, **kw: original(self, *args, **kw)
824 else:
825 # only set _new_name and not name so that mock_calls is tracked
826 # but not method calls
827 _check_and_set_parent(self, value, None, name)
828 setattr(type(self), name, value)
829 self._mock_children[name] = value
830 elif name == '__class__':
831 self._spec_class = value
832 return
833 else:
834 if _check_and_set_parent(self, value, name, name):
835 self._mock_children[name] = value
836
837 if self._mock_sealed and not hasattr(self, name):
838 mock_name = f'{self._extract_mock_name()}.{name}'
839 raise AttributeError(f'Cannot set {mock_name}')
840
841 if isinstance(value, PropertyMock):
842 self.__dict__[name] = value
843 return
844 return object.__setattr__(self, name, value)
845
846
847 def __delattr__(self, name):

Callers

nothing calls this directly

Calls 7

_extract_mock_nameMethod · 0.95
_is_instance_mockFunction · 0.85
setattrFunction · 0.85
_get_methodFunction · 0.85
_check_and_set_parentFunction · 0.85
hasattrFunction · 0.85
isinstanceFunction · 0.85

Tested by

no test coverage detected