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
My question/issue is related to __attrs_init_subclass__ that was recently added.
PEP 487 allows for passing arguments (not sure whether that's the proper name) at class definition.
The use case, for me, would be to have some sort of abstract class attributes that should be defined by concrete classes.
To make it short, reusing the example from the docs, this works
classBase:
@classmethoddef__init_subclass__(cls, foo):
cls.foo=fooprint(f"Base has been subclassed by attrs {cls} and foo={cls.foo}.")
classDerived(Base, foo=42):
pass
>>> Base has been subclassed by attrs <class '__main__.Derived'> and foo=42.
while
importattrsclassBase:
@classmethoddef__attrs_init_subclass__(cls, foo):
cls.foo=fooprint(f"Base has been subclassed by attrs {cls} and foo={cls.foo}.")
@attrs.defineclassDerived(Base, foo=12):
pass
does not, throwing TypeError: Derived.__init_subclass__() takes no keyword arguments.
Would there be any workaround?
The text was updated successfully, but these errors were encountered:
Hello, thanks for the great work!
My question/issue is related to
__attrs_init_subclass__
that was recently added.PEP 487 allows for passing arguments (not sure whether that's the proper name) at class definition.
The use case, for me, would be to have some sort of abstract class attributes that should be defined by concrete classes.
To make it short, reusing the example from the docs, this works
>>> Base has been subclassed by attrs <class '__main__.Derived'> and foo=42.
while
does not, throwing
TypeError: Derived.__init_subclass__() takes no keyword arguments
.Would there be any workaround?
The text was updated successfully, but these errors were encountered: