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
{{ message }}
Repository navigation
Missing import in example at dataclasses.rst #91673
Sure @ericvsmith, but the example in the documentation doesn't run.
Your suggestion for using list instead of list works, as long it is defined as x: list = field(default_factory=list).
However, I think the example is about forcing the datatype in the list using List from typing.
This works (as example only):
from dataclasses import dataclass
from typing import List
@dataclass
class User:
x: list = field(default_factory=list)
y: List[int] = field(default_factory=list)
this doesn't work
from dataclasses import dataclass
@dataclass
class User:
x: list = []
Activity
ericvsmith commentedon Apr 18, 2022
I'm not sure how important this is. The example already says the code isn't valid. Maybe just use "list" instead of "List".
xandrade commentedon Apr 18, 2022
Sure @ericvsmith, but the example in the documentation doesn't run.
Your suggestion for using list instead of list works, as long it is defined as
x: list = field(default_factory=list).However, I think the example is about forcing the datatype in the list using List from typing.
This works (as example only):
this doesn't work