Message 403277 - Python tracker

Message403277

Author GBeauregard
Recipients GBeauregard
Date 2021-10-05.23:00:02
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1633474802.74.0.28935369268.issue45384@roundup.psfhosted.org>
In-reply-to
Content
PEP 591 for the Final Attribute states "Type checkers should infer a final attribute that is initialized in a class body as being a class variable. Variables should not be annotated with both ClassVar and Final."

This is a bit of a typing conflict for dataclasses, where ClassVar is used to indicate a desired library behavior, but one may want to indicate Final.

I propose accepting the Final attribute as an indicator of a ClassVar in dataclasses class bodies in order to be better compatible with the Final PEP.

There is at least one edge case that would need to be handled where someone might want to explicitly mark a dataclass field Final, which could be allowed as a field:
a: Final[int] = dataclasses.field(init=False, default=10)
History
Date User Action Args
2021-10-05 23:00:02GBeauregardsetrecipients: + GBeauregard
2021-10-05 23:00:02GBeauregardsetmessageid: <1633474802.74.0.28935369268.issue45384@roundup.psfhosted.org>
2021-10-05 23:00:02GBeauregardlinkissue45384 messages
2021-10-05 23:00:02GBeauregardcreate