MCPcopy Index your code
hub / github.com/dabeaz-course/python-mastery / create_init

Method create_init

Solutions/7_4/structure.py:25–35  ·  view source on GitHub ↗

Create an __init__ method from _fields

(cls)

Source from the content-addressed store, hash-verified

23
24 @classmethod
25 def create_init(cls):
26 '''
27 Create an __init__ method from _fields
28 '''
29 args = ','.join(cls._fields)
30 code = f'def __init__(self, {args}):\n'
31 for name in cls._fields:
32 code += f' self.{name} = {name}\n'
33 locs = { }
34 exec(code, locs)
35 cls.__init__ = locs['__init__']
36
37 @classmethod
38 def __init_subclass__(cls):

Callers 1

validate_attributesFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected