diff options
author | Eric V. Smith <ericvsmith@users.noreply.github.com> | 2021-11-22 13:26:12 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-11-22 13:26:12 (GMT) |
commit | d3062f672c92855b7e9e962ad4bf1a67abd4589b (patch) | |
tree | 6820af4d14c25fb50287439c821d86d4fa39f7c5 /Misc | |
parent | 5b946cadaa1175a5caae98bd2d309840bea52a58 (diff) | |
download | cpython-d3062f672c92855b7e9e962ad4bf1a67abd4589b.zip cpython-d3062f672c92855b7e9e962ad4bf1a67abd4589b.tar.gz cpython-d3062f672c92855b7e9e962ad4bf1a67abd4589b.tar.bz2 |
bpo-44649: Fix dataclasses(slots=True) with a field with a default, but init=False (GH-29692)
Special handling is needed, because for non-slots dataclasses the instance attributes are not set: reading from a field just references the class's attribute of the same name, which contains the default value. But this doesn't work for classes using __slots__: they don't read the class's attribute. So in that case (and that case only), initialize the instance attribute. Handle this for both normal defaults, and for fields using default_factory.
Diffstat (limited to 'Misc')
-rw-r--r-- | Misc/NEWS.d/next/Library/2021-11-21-20-50-42.bpo-44649.E8M936.rst | 2 |
1 files changed, 2 insertions, 0 deletions
diff --git a/Misc/NEWS.d/next/Library/2021-11-21-20-50-42.bpo-44649.E8M936.rst b/Misc/NEWS.d/next/Library/2021-11-21-20-50-42.bpo-44649.E8M936.rst new file mode 100644 index 0000000..f6391a9 --- /dev/null +++ b/Misc/NEWS.d/next/Library/2021-11-21-20-50-42.bpo-44649.E8M936.rst @@ -0,0 +1,2 @@ +Handle dataclass(slots=True) with a field that has default a default value, +but for which init=False. |