[Python-Dev] We should accept Final as indicating ClassVar for dataclasses
177 views
Skip to first unread message
Gregory Beauregard via Python-Dev
unread,
Oct 8, 2021, 11:11:51 PM10/8/21
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to pytho...@python.org
(copied from typing on advice since this affects runtime behavior)
PEP 591 for Final 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."
ClassVar is used to indicate library behavior in dataclasses. Therefore, I propose accepting the Final attribute as an indicator of a ClassVar in dataclass class bodies in order to be better compatible with the Final PEP.
One edge case that would need to be handled is when someone might explicitly mark a dataclass field Final:
a: Final[int] = dataclasses.field(init=False, default=10)