You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@auto_init('height')classWall(object):
height: int=field(doc="Height of the wall in mm.")
color: str=field(default='white', doc="Color of the wall.")
pros
a simple decorator, and "all fields" is easy to declare: decorator without arguments.
cons
fields are referenced by name: no autocompletion if a particular selection needs to be made.
decorator = a bit harder to debug and can be frightening
5b with decorator but fields declare if they are in init
@auto_initclassWall(object):
height: int=field(doc="Height of the wall in mm.", in_init=True)
color: str=field(default='white', doc="Color of the wall.", in_init=False)
pros
more compact decoration
cons
I do not like the fact that the inclusion in init is a property of the fields. This will cause trouble in inheritance and mixin scenarii.
5c explicit method
classWall(object):
height: int=field(doc="Height of the wall in mm.")
color: str=field(default='white', doc="Color of the wall.")
__init__=make_init(height, color)
pros
compact
autocompletion works if an explicit list or order needs to be provided
this can probably be smoothly extended to support scenario 4 as well (a __post_init__ method or even any method using make_init(..., post=<method_post>) or make_init(color, my_post_init_method, height) so as to control precisely which part of the signature will go where)
feature 5
5a with decorator
pros
cons
5b with decorator but fields declare if they are in init
pros
cons
5c explicit method
pros
__post_init__
method or even any method usingmake_init(..., post=<method_post>)
ormake_init(color, my_post_init_method, height)
so as to control precisely which part of the signature will go where)I do not see much cons here
Originally posted by @smarie in #2 (comment)
The text was updated successfully, but these errors were encountered: