-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Closed
Labels
Description
Bug Report
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):[mypy] ignore_missing_imports = True follow_imports = silent show_column_numbers = True check_untyped_defs = True
- Python version used: 3.8.2
vnmabus, mudassirkhan19 and Fearchar