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
Appreciate the help if anybody has ideas. Here's a minified example of what I mean:
fromtypingimportProtocol, ClassVarclassClassWithFlag(Protocol):
flag: ClassVar[bool]
classTrueFlag:
flag=TrueclassFalseFlag:
flag: ClassVar=Falseflagged: type[ClassWithFlag] =TrueFlag# error: "flag" is not a class variableflagged2: type[ClassWithFlag] =FalseFlag# not error
Both mypy and pyright give the same error. I understand the logic that ClassVar is stricter than just "variable on the class": it also means an instance isn't allowed to overwrite the value.
I wish protocol implementers didn't have to provide the ClassVar annotation.
Should I get rid of the type and just have a protocol that applies to the class instead?
But, that can't be combined with TypeVar -- there's no "and" combination of types, so I can't say "this is both a TypeVar AND implements the Protocol".
Closest related other discussion I could find was this: #1056
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Appreciate the help if anybody has ideas. Here's a minified example of what I mean:
Both mypy and pyright give the same error. I understand the logic that
ClassVar
is stricter than just "variable on the class": it also means an instance isn't allowed to overwrite the value.I wish protocol implementers didn't have to provide the
ClassVar
annotation.Should I get rid of the
type
and just have a protocol that applies to the class instead?But, that can't be combined with
TypeVar
-- there's no "and" combination of types, so I can't say "this is both a TypeVar AND implements the Protocol".Closest related other discussion I could find was this: #1056
Beta Was this translation helpful? Give feedback.
All reactions