classification
Title: dataclasses.replace raises an exception if InitVar with default argument is not provided.
Type: behavior Stage: patch review
Components: Interpreter Core Versions: Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: eric.smith Nosy List: Greg Kuhn, eric.smith, levkivskyi, mierzej
Priority: normal Keywords: patch

Created on 2019-03-29 11:52 by Greg Kuhn, last changed 2019-12-02 20:17 by Claudiu.Popa.

Pull Requests
URL Status Linked Edit
PR 17441 open Claudiu.Popa, 2019-12-02 20:17
Messages (2)
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
History
Date User Action Args
2019-12-02 20:17:37Claudiu.Popasetkeywords: + patch
stage: patch review
pull_requests: + pull_request16922
2019-10-01 20:40:45eric.smithsetassignee: eric.smith
2019-04-09 13:19:15mierzejsetnosy: + mierzej
2019-03-29 19:55:59levkivskyisetnosy: + levkivskyi
2019-03-29 16:12:06Greg Kuhnsetmessages: + msg339124
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:41xtreaksetnosy: + eric.smith
2019-03-29 11:52:18Greg Kuhncreate