Message 403617 - Python tracker

Message403617

Author carljm
Recipients GBeauregard, carljm, eric.smith, saaketp
Date 2021-10-11.05:06:22
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1633928783.1.0.683096130485.issue45384@roundup.psfhosted.org>
In-reply-to
Content
Good idea to check with the PEP authors. 

I don’t think allowing both ClassVar and Final in dataclasses requires general intersection types. Neither ClassVar nor Final are real types; they aren’t part of the type of the value.  They are more like special annotations on a name, which are wrapped around a type as syntactic convenience. You’re right that it would require more than just amendment to the PEP text, though; it might require changes to type checkers, and it would also require changes to the runtime behavior of the `typing` module to special-case allowing `ClassVar[Final[…]]`. And the downside of this change is that it couldn’t be context sensitive to only be allowed in dataclasses. But I think this isn’t a big problem; type checkers could still error on that wrapping in non dataclass contexts if they want to. 

But even if that change can’t be made, I think backwards compatibility still precludes changing the interpretation of `x: Final[int] = 3` on a dataclass, and it is more valuable to be able to specify Final instance attributes (fields) than final class attributes on dataclasses.
History
Date User Action Args
2021-10-11 05:06:23carljmsetrecipients: + carljm, eric.smith, GBeauregard, saaketp
2021-10-11 05:06:23carljmsetmessageid: <1633928783.1.0.683096130485.issue45384@roundup.psfhosted.org>
2021-10-11 05:06:23carljmlinkissue45384 messages
2021-10-11 05:06:22carljmcreate