-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Labels
affects-typeshedAnything that blocks a typeshed changeAnything that blocks a typeshed changebugmypy got something wrongmypy got something wrongfalse-positivemypy gave an error on correct codemypy gave an error on correct codepriority-0-highsize-largetopic-descriptorsProperties, class vs. instance attributesProperties, class vs. instance attributes
Description
Consider this example:
from typing import Callable
class A:
f = None # type: Callable[[int], int]
def __init__(self, g: Callable[[int], int]) -> None:
self.f = g
mypy reports:
trial.py: In member "__init__" of class "A":
trial.py, line 7: Cannot assign to a method
trial.py, line 7: Invalid method type
trial.py, line 7: Incompatible types in assignment (expression has type Callable[[int], int], variable has type Callable[[], int])
while I'd expect this to work.
Note that there is a second error in the reporting of the type of the variable.
Also, this passes type checking (correctly):
f = None # type: Callable[[int], int]
def g(x: int) -> int: return 0
f = g
ariddell, tsileo, reallistic, ilevkivskyi, ncvc and 83 more
Metadata
Metadata
Assignees
Labels
affects-typeshedAnything that blocks a typeshed changeAnything that blocks a typeshed changebugmypy got something wrongmypy got something wrongfalse-positivemypy gave an error on correct codemypy gave an error on correct codepriority-0-highsize-largetopic-descriptorsProperties, class vs. instance attributesProperties, class vs. instance attributes