This is definitely possible, here is a somewhat naive implementation:
def lazy_init(init): import inspect arg_names = inspect.getargspec(init)[0] def new_init(self, *args): for name, value in zip(arg_names[1:], args): setattr(self, name, value) init(self, *args) return new_init class Person: @lazy_init def __init__(self, name, age): pass p = Person("Derp", 13) print p.name, p.age
As soon as you start to have something besides the attributes that appear in the properties, you are faced with a problem. You will need at least some way to indicate which arguments are initialized as properties ... at this point it will just become more complex than it costs.
Matti Virkkunen
source share