New submission from Anthony <>:

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 <>
Python-bugs-list mailing list

Reply via email to