from dataclasses import field, dataclass
custom_field = field()
@dataclass
class A:
x: int
y: int = custom_field
z: int = custom_field
A(x=1, y=2, z=3)
After executing the following code I get this error:
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-8-1314913987c2> in <module>
----> 1 A(x=1, y=2, z=3)
TypeError: __init__() got an unexpected keyword argument 'y'
I can overcome this issue by using the following code:
from dataclasses import field, dataclass
custom_field = lambda: field()
@dataclass
class A:
x: int
y: int = custom_field()
z: int = custom_field()
A(x=1, y=2, z=3)
Tested with python 3.7.9