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
from dataclasses import dataclass
from io import StringIO
from dataclass_csv import DataclassReader
class C:
def __init__(self, x):
print(f"initialized with {x!r}")
self.x = x
@dataclass
class Row:
b: int
c: C = C(5)
# initialized with 5
A = list(DataclassReader(StringIO("b,c\n1,"), Row))
# initialized with <__main__.C object at 0x10385ea90>
print(A[0].c.x)
# <__main__.C at 0x10385ea90>
This generalises #20.
I completed the example from the README. The following works.
After replacing the SSN in the data with a default value, the error below occurs.
The reason being that the SSN constructor is called with the default value, which is an object. The next snippet works around that.
But now this class can no longer be instantiated directly without creating broken objects, and type checkers will complain.
I think if a default value exists it should be used as is, and not passed to the constructor of its class.
The text was updated successfully, but these errors were encountered: