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

Method create_init

Solutions/7_6/structure.py:37–47  ·  view source on GitHub ↗

Create an __init__ method from _fields

(cls)

Source from the content-addressed store, hash-verified

35
36 @classmethod
37 def create_init(cls):
38 '''
39 Create an __init__ method from _fields
40 '''
41 args = ','.join(cls._fields)
42 code = f'def __init__(self, {args}):\n'
43 for name in cls._fields:
44 code += f' self.{name} = {name}\n'
45 locs = { }
46 exec(code, locs)
47 cls.__init__ = locs['__init__']
48
49 @classmethod
50 def __init_subclass__(cls):

Callers 1

validate_attributesFunction · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected