MCPcopy Create free account
hub / github.com/dabeaz-course/python-mastery / create_init

Method create_init

Solutions/9_3/structly/structure.py:45–55  ·  view source on GitHub ↗

Create an __init__ method from _fields

(cls)

Source from the content-addressed store, hash-verified

43
44 @classmethod
45 def create_init(cls):
46 '''
47 Create an __init__ method from _fields
48 '''
49 args = ','.join(cls._fields)
50 code = f'def __init__(self, {args}):\n'
51 for name in cls._fields:
52 code += f' self.{name} = {name}\n'
53 locs = { }
54 exec(code, locs)
55 cls.__init__ = locs['__init__']
56
57 @classmethod
58 def __init_subclass__(cls):

Callers 1

validate_attributesFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected