Issue 36470: dataclasses.replace raises an exception if InitVar with default argument is not provided. (original) (raw)

Issue36470

This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

This issue has been migrated to GitHub: https://github.com/python/cpython/issues/80651

classification

Title: dataclasses.replace raises an exception if InitVar with default argument is not provided.
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.7

process

Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: eric.smith Nosy List: Greg Kuhn, ZackerySpytz, anthrotype, eric.smith, levkivskyi, mierzej, miss-islington
Priority: normal Keywords: patch

Created on 2019-03-29 11:52 by Greg Kuhn, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 17441 closed Claudiu.Popa,2019-12-02 20:17
PR 20867 merged ZackerySpytz,2020-06-14 05:38
PR 25200 merged miss-islington,2021-04-05 19:41
PR 25201 merged miss-islington,2021-04-05 19:41
Messages (7)
msg339105 - (view) Author: Greg Kuhn (Greg Kuhn) Date: 2019-03-29 11:52
I have a snippet below which runs fine on python 3.7.0 but raises a ValueError exception on 3.7.1. I believe it's related to https://bugs.python.org/issue33805. The error: c:\python\lib\dataclasses.py:1219: ValueError The script: from dataclasses import replace, dataclass, InitVar @dataclass class Test: a:int = 1 b:InitVar[int] = None def __post_init__(self, b): if b is not None: self.a = b if __name__ == '__main__': t = Test() t1 = Test(b=5) assert t1.a == 5 t2 = replace(t1, **{}) print(t2)
msg339124 - (view) Author: Greg Kuhn (Greg Kuhn) Date: 2019-03-29 16:12
Fixed title
msg385914 - (view) Author: Cosimo Lupo (anthrotype) Date: 2021-01-29 15:09
any updates on this? Would be great if any of the two candidate PRs was merged. It's basically impossible to use replace() with default InitVars.. Thank you in advace
msg390252 - (view) Author: miss-islington (miss-islington) Date: 2021-04-05 19:41
New changeset 75220674c07abfc90c2cd7862d04cfa2e2354450 by Zackery Spytz in branch 'master': bpo-36470: Allow dataclasses.replace() to handle InitVars with default values (GH-20867) https://github.com/python/cpython/commit/75220674c07abfc90c2cd7862d04cfa2e2354450
msg390256 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2021-04-05 20:07
New changeset bdee2a389e4b10e1c0ab65bbd4fd03defe7b2837 by Miss Islington (bot) in branch '3.8': bpo-36470: Allow dataclasses.replace() to handle InitVars with default values (GH-20867) (GH-25201) https://github.com/python/cpython/commit/bdee2a389e4b10e1c0ab65bbd4fd03defe7b2837
msg390257 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2021-04-05 20:07
New changeset 013c30e5fcee449cee63354d34585d6111782c82 by Miss Islington (bot) in branch '3.9': bpo-36470: Allow dataclasses.replace() to handle InitVars with default values (GH-20867) (GH-25200) https://github.com/python/cpython/commit/013c30e5fcee449cee63354d34585d6111782c82
msg390259 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2021-04-05 20:12
Thanks for the fix!
History
Date User Action Args
2022-04-11 14:59:13 admin set github: 80651
2021-04-05 20:12:35 eric.smith set status: open -> closedresolution: fixedmessages: + stage: patch review -> resolved
2021-04-05 20:07:42 eric.smith set messages: +
2021-04-05 20:07:39 eric.smith set messages: +
2021-04-05 19:41:23 miss-islington set pull_requests: + <pull%5Frequest23940>
2021-04-05 19:41:16 miss-islington set pull_requests: + <pull%5Frequest23939>
2021-04-05 19:41:09 miss-islington set nosy: + miss-islingtonmessages: +
2021-01-29 15:09:54 anthrotype set nosy: + anthrotypemessages: +
2020-06-14 05:38:50 ZackerySpytz set nosy: + ZackerySpytzpull_requests: + <pull%5Frequest20056>
2019-12-02 20:17:37 Claudiu.Popa set keywords: + patchstage: patch reviewpull_requests: + <pull%5Frequest16922>
2019-10-01 20:40:45 eric.smith set assignee: eric.smith
2019-04-09 13:19:15 mierzej set nosy: + mierzej
2019-03-29 19:55:59 levkivskyi set nosy: + levkivskyi
2019-03-29 16:12:06 Greg Kuhn set messages: + title: dataclasses replace raises an exception with an empty -> dataclasses.replace raises an exception if InitVar with default argument is not provided.
2019-03-29 11:57:41 xtreak set nosy: + eric.smith
2019-03-29 11:52:18 Greg Kuhn create