Author sigurd
Recipients sigurd
Date 2018-06-07.14:34:49
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1528382089.85.0.592728768989.issue33796@psf.upfronthosting.co.za>
In-reply-to
Content
The dataclasses.replace function does not work for classes that have class variables. See the console output below for an example.

$ python
Python 3.7.0b5+ (heads/3.7:3c417610ad, Jun  7 2018, 16:21:29) 
[Clang 9.1.0 (clang-902.0.39.2)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import typing
>>> import dataclasses
>>> @dataclasses.dataclass(frozen=True)
... class Test:
...   a: int
...   class_var: typing.ClassVar[str] = 'foo'
... 
>>> obj = Test(a=1)
>>> dataclasses.replace(obj, a=2)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/sigurdljodal/.pyenv/versions/3.7-dev/lib/python3.7/dataclasses.py", line 1179, in replace
    return obj.__class__(**changes)
TypeError: __init__() got an unexpected keyword argument 'class_var'
History
Date User Action Args
2018-06-07 14:34:49sigurdsetrecipients: + sigurd
2018-06-07 14:34:49sigurdsetmessageid: <1528382089.85.0.592728768989.issue33796@psf.upfronthosting.co.za>
2018-06-07 14:34:49sigurdlinkissue33796 messages
2018-06-07 14:34:49sigurdcreate