You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Depending on the annotation source (a class, a function parameter, etc), different type qualifiers are allowed. For classes, users can use Final or ClassVar:
classA:
a: ClassVar[int]
b: Final[str]
However, it seems like ClassVar and Final can't be used together. Code sample in pyright playground:
fromtypingimportClassVar, FinalclassA:
a: Final[ClassVar[int]] # "ClassVar" is not allowed in this contextb: ClassVar[Final[int]] # "Final" is not allowed in this context
There is currently no logic to disallow this. Is it worth checking for this?
As a side note, combining ClassVar and Final is allowed for dataclasses (and types using @dataclass_transform).
The text was updated successfully, but these errors were encountered:
Viicos
added
the
open issues
Open issues to be discussed with other users of the runtime typing ecosystem
label
Feb 18, 2025
In the
introspection
module, theinspect_annotation()
function can be used to unpack the underlying type expression of an annotation, by stripping and keeping track of the type qualifiers used:Depending on the annotation source (a class, a function parameter, etc), different type qualifiers are allowed. For classes, users can use
Final
orClassVar
:However, it seems like
ClassVar
andFinal
can't be used together. Code sample in pyright playground:There is currently no logic to disallow this. Is it worth checking for this?
As a side note, combining
ClassVar
andFinal
is allowed for dataclasses (and types using@dataclass_transform
).The text was updated successfully, but these errors were encountered: