Issue 32896: Error when subclassing a dataclass with a field that uses a defaultfactory (original) (raw)

Issue32896

Created on 2018-02-21 16:21 by John Didion, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 6170 merged eric.smith,2018-03-21 00:52
PR 6171 merged miss-islington,2018-03-21 02:01
Messages (5)
msg312496 - (view) Author: John Didion (John Didion) Date: 2018-02-21 16:21
> @dataclass > class Foo: > x: dict = field(default_factory=dict) > @dataclass > class Bar(Foo): > y: int = 1 > @dataclass > class Baz(Foo): > def blorf(self): > print('hello') > Foo().x {} > Bar().x {} > Baz().x Traceback (most recent call last): File "", line 1, in TypeError: __init__() missing 1 required positional argument: 'x' --- I understand that this is desired behavior when the subclass contains non-default attributes. But subclasses that define no additional attributes should work just the same as those that define only additional default attributes. A similar issue was raised and dismissed when dataclasses was in development on GitHub: https://github.com/ericvsmith/dataclasses/issues/112, but that only concerned the case of subclasses defining non-default attributes.
msg312517 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2018-02-22 00:16
That's a great bug report. Thanks for the tiny code to replicate it. It turns out the code isn't quite doing what I thought. I'll have to give some thought to exactly how I'm going to handle this without breaking other cases, but I should have it fixed soon. Thanks again.
msg314182 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2018-03-21 02:00
New changeset 8f6eccdc64cab735c47620fea948e64b19f83684 by Eric V. Smith in branch 'master': bpo-32896: Fix error when subclassing a dataclass with a field that uses a default_factory (GH-6170) https://github.com/python/cpython/commit/8f6eccdc64cab735c47620fea948e64b19f83684
msg314188 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2018-03-21 09:22
New changeset 22136c94b6e43c8c584a54f3a513b83b753b96ee by Eric V. Smith (Miss Islington (bot)) in branch '3.7': bpo-32896: Fix error when subclassing a dataclass with a field that uses a default_factory (GH-6170) (GH-6171) https://github.com/python/cpython/commit/22136c94b6e43c8c584a54f3a513b83b753b96ee
msg314189 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2018-03-21 09:23
Thanks again for the bug report. This ended up being a simple fix, but an important one.
History
Date User Action Args
2022-04-11 14:58:58 admin set nosy: + lukasz.langagithub: 77077
2018-03-21 09:23:12 eric.smith set status: open -> closedresolution: fixedmessages: + stage: patch review -> resolved
2018-03-21 09:22:08 eric.smith set messages: +
2018-03-21 02:01:50 miss-islington set pull_requests: + <pull%5Frequest5926>
2018-03-21 02:00:26 eric.smith set messages: +
2018-03-21 00:52:04 eric.smith set keywords: + patchstage: patch reviewpull_requests: + <pull%5Frequest5925>
2018-03-21 00:50:47 eric.smith set priority: deferred blocker -> release blockerversions: + Python 3.8
2018-02-26 14:03:04 eric.smith set priority: release blocker -> deferred blocker
2018-02-22 00:17:05 eric.smith set priority: normal -> release blockernosy: + ned.deily
2018-02-22 00:16:04 eric.smith set messages: +
2018-02-21 18:43:45 eric.smith set assignee: eric.smithtype: crash -> behaviorcomponents: + Library (Lib)
2018-02-21 16:36:54 ned.deily set nosy: + eric.smith
2018-02-21 16:21:46 John Didion create