Message356306
Given one of the motivations of @dataclass is to reduce boilerplate code then, in the context of @dataclass,
x: list = [] should be equal to x: list = field(default_factory=lambda: [])
The example in PEP 557 is not reasonable. It should be:
class D:
def __init__(self, x=[]):
self.x = x
That x = None works (without specifying a default factory, and is different from plain "x") makes the whole "factory" argument even more bizarre. Why would a None Type work, but a List Type not?
I think either the behavior of this should be different or the docs should at address this more clearly. |
|
Date |
User |
Action |
Args |
2019-11-09 20:29:38 | anthony | set | recipients:
+ anthony |
2019-11-09 20:29:38 | anthony | set | messageid: <1573331378.39.0.720825104311.issue38758@roundup.psfhosted.org> |
2019-11-09 20:29:38 | anthony | link | issue38758 messages |
2019-11-09 20:29:38 | anthony | create | |
|