MCPcopy Create free account
hub / github.com/bslatkin/effectivepython / __setattr__

Method __setattr__

example_code/item_056_example_12.py:34–39  ·  view source on GitHub ↗
(self, key: str, value: Any)

Source from the content-addressed store, hash-verified

32 self.y = y
33
34 def __setattr__(self, key: str, value: Any) -> None:
35 if key in self.__annotations__ and key not in dir(self):
36 # Allow the very first assignment to happen
37 super().__setattr__(key, value)
38 else:
39 raise AttributeError("Immutable object")
40
41 def __delattr__(self, key: str) -> Never:
42 raise AttributeError("Immutable object")

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected