New submission from Gregory Beauregard <g...@greg.red>:

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)

----------
components: Library (Lib)
messages: 403277
nosy: GBeauregard
priority: normal
severity: normal
status: open
title: Accept Final as indicating ClassVar for dataclass
type: enhancement

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue45384>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to