]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
bpo-44674: Use unhashability as a proxy for mutability for default dataclass __init__...
authorEric V. Smith <ericvsmith@users.noreply.github.com>
Sat, 11 Dec 2021 21:12:17 +0000 (16:12 -0500)
committerGitHub <noreply@github.com>
Sat, 11 Dec 2021 21:12:17 +0000 (16:12 -0500)
commite029c53e1a408b89a4e3edf30a9b38b094f9c880
treea439835a4dd477b67b500e5d09ff82b739973791
parentbfc59ed0a00106f5ba4a32a0c5b3dbe71d12665d
bpo-44674: Use unhashability as a proxy for mutability for default dataclass __init__ arguments. (GH-29867)

`@dataclass` in 3.10 prohibits using list, dict, or set as default values. It does this to avoid the mutable default problem. This test is both too strict, and not strict enough. Too strict, because some immutable subclasses should be safe, and not strict enough, because other mutable types should be prohibited. With this change applied, `@dataclass` now uses unhashability as a proxy for mutability: if objects aren't hashable, they're assumed to be mutable.
Doc/library/dataclasses.rst
Lib/dataclasses.py
Lib/test/test_dataclasses.py
Misc/NEWS.d/next/Library/2021-11-29-19-37-20.bpo-44674.NijWLt.rst [new file with mode: 0644]