[Tutor] there might be something error in dataclasses.py

LI Bonjour z at bonjourpy.org
Thu Jul 8 02:51:43 EDT 2021


>>> from dataclasses import dataclass
>>> @dataclass
... class A:
...     a:list[str] = None
...
...
>>> a = A()
>>> a.a = []
>>> b
[A(a=['1']), A(a=['1']), A(a=['1'])]
>>> for x in b:
...     x.a.append('1')
...
>>> b
[A(a=['1', '1', '1', '1']), A(a=['1', '1', '1', '1']), A(a=['1', '1', '1', '1'])]
>>>
I think it should be this below.
 [A(a=['1','1']), A(a=['1','1']), A(a=['1','1'])]
is there anything wrong here .
please mail me ASAP,thanks




More information about the Tutor mailing list