New submission from Anthony <[email protected]>:
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 <[email protected]>
<https://bugs.python.org/issue38758>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com