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

Class ValidatingRecord

example_code/item_061.py:86–100  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

84
85print("Example 4")
86class ValidatingRecord:
87 def __init__(self):
88 self.exists = 5
89
90 def __getattribute__(self, name):
91 print(f"* Called __getattribute__({name!r})")
92 try:
93 value = super().__getattribute__(name)
94 print(f"* Found {name!r}, returning {value!r}")
95 return value
96 except AttributeError:
97 value = f"Value for {name}"
98 print(f"* Setting {name!r} to {value!r}")
99 setattr(self, name, value)
100 return value
101
102data = ValidatingRecord()
103print("exists: ", data.exists)

Callers 1

item_061.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected