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

2021-05-04 Thread Eric V. Smith
Eric V. Smith added the comment: I don’t see any way of changing this behavior, so I’m going to close this issue. -- resolution: -> rejected stage: -> resolved status: open -> closed ___ Python tracker

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

2021-04-27 Thread Eric V. Smith
Eric V. Smith added the comment: I'm not aware of what problems it would cause, but there's no doubt someone who's relying on it. Since it's a behavior of normal classes, changing it would violate dataclasses desire (not always realized) to have as little impact as possible on the class tha

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

2021-04-27 Thread Sergei Lebedev
Sergei Lebedev added the comment: I understand that this is a side-effect of having a default value, but I was hoping we could delattr InitVar's in @dataclass. I'm not aware of this causing problems, but it does feel a bit unsatisfying that InitVar's with defaults are kept in the class name

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

2021-04-27 Thread Eric V. Smith
Change by Eric V. Smith : -- assignee: -> eric.smith type: -> behavior versions: -Python 3.11, Python 3.7, Python 3.8 ___ Python tracker ___

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

2021-04-27 Thread Eric V. Smith
Eric V. Smith added the comment: This is just how Python works. The default values for .x and .y are set on the class A, not its instances. Here's the equivalent without dataclasses: >>> class A: ... x = 0 ... y = 1 ... >>> a = A() >>> a.x 0 >>> a.y 1 >>> a.__dict__ {} >>> A.__dict__ mapp

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

2021-04-27 Thread Sergei Lebedev
New submission from Sergei Lebedev : Motivating example: >>> @dataclass ... class A: ... x: InitVar[int] = 0 ... y: int = 1 ... >>> a = A() >>> a.x 0 >>> a.y 1 PEP-557 does not specify if fields annotated with InitVar[...] are available on the resulting dataclass. However, they are not p