We should accept Final as indicating ClassVar for dataclasses

(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) I've opened an issue as well and would greatly appreciate any feedback: https://bugs.python.org/issue45384 I appreciate your time, Gregory Beauregard
participants (1)
-
Gregory Beauregard