MCPcopy Index your code
hub / github.com/bslatkin/effectivepython / __new__

Method __new__

example_code/item_062.py:192–197  ·  view source on GitHub ↗
(meta, name, bases, class_dict)

Source from the content-addressed store, hash-verified

190
191class ValidateFilledPolygon(ValidatePolygon):
192 def __new__(meta, name, bases, class_dict):
193 # Only validate non-root classes
194 if not class_dict.get("is_root"):
195 if class_dict["color"] not in ("red", "green"):
196 raise ValueError("Fill color must be supported")
197 return super().__new__(meta, name, bases, class_dict)
198
199class FilledPolygon(Polygon, metaclass=ValidateFilledPolygon):
200 is_root = True

Callers

nothing calls this directly

Calls 2

getMethod · 0.45
__new__Method · 0.45

Tested by

no test coverage detected