[New-bugs-announce] [issue38758] @dataclass defaults
Anthony
report at bugs.python.org
Sat Nov 9 15:29:38 EST 2019
New submission from Anthony <anthonysarkis at gmail.com>:
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.
----------
components: Interpreter Core
messages: 356306
nosy: anthony
priority: normal
severity: normal
status: open
title: @dataclass defaults
type: behavior
versions: Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue38758>
_______________________________________
More information about the New-bugs-announce
mailing list