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

Method __getattr__

example_code/item_061.py:111–116  ·  view source on GitHub ↗
(self, name)

Source from the content-addressed store, hash-verified

109try:
110 class MissingPropertyRecord:
111 def __getattr__(self, name):
112 if name == "bad_name":
113 raise AttributeError(f"{name} is missing")
114 value = f"Value for {name}"
115 setattr(self, name, value)
116 return value
117
118 data = MissingPropertyRecord()
119 assert data.foo == "Value for foo" # Test this works

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected