[New-bugs-announce] [issue43953] InitVar should not be available on a @dataclass-decorated class

Sergei Lebedev report at bugs.python.org
Tue Apr 27 07:54:00 EDT 2021

New submission from Sergei Lebedev <sergei.a.lebedev at gmail.com>:

Motivating example:

>>> @dataclass
... class A:
...   x: InitVar[int] = 0
...   y: int = 1
>>> a = A()
>>> a.x
>>> a.y

PEP-557 does not specify if fields annotated with InitVar[...] are available on the resulting dataclass. However, they are not part of the dataclass structure and are only used for __*init__ generation, so perhaps they shouldn't be? Wdyt?

components: Library (Lib)
messages: 392058
nosy: eric.smith, superbobry
priority: normal
severity: normal
status: open
title: InitVar should not be available on a @dataclass-decorated class
versions: Python 3.10, Python 3.11, Python 3.7, Python 3.8, Python 3.9

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list