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
This program ought to be valid, because all the protocol Foo is declaring is that the attribute foo is readable and returns an int. This requirement is met by Bar's class variable.
from typing import *
class Foo(Protocol):
@property
def foo(self) -> int:
...
class Bar:
foo : ClassVar[int] = 42
x : Foo = Bar()
However, mypy says Protocol member Foo.foo expected instance variable, got class variablemypy.
if you just declare foo : int = 42, mypy accepts it, so clearly it understands that variables qualify as read-only properties, just not class variables.
Your Environment
Mypy version used: 0.812
Mypy configuration options from mypy.ini (and other config files):
Bug Report
This program ought to be valid, because all the protocol
Foo
is declaring is that the attributefoo
is readable and returns anint
. This requirement is met byBar
's class variable.However, mypy says
Protocol member Foo.foo expected instance variable, got class variablemypy
.if you just declare
foo : int = 42
, mypy accepts it, so clearly it understands that variables qualify as read-only properties, just not class variables.Your Environment
mypy.ini
(and other config files):The text was updated successfully, but these errors were encountered: