Describe the bug
Environment: Ubuntu 18.04, pyright 1.1.48, Python 3.6.
If an instance variable of Callable type is not initialized in __init__ method, Pyright always regards its type as Callable with no arguments.
For example, Pyright reports two errors in code below, but when I run python3 code.py, the code outputs 2 with no errors.
```:code.py
from typing import Callable
def add1(n: int):
return n + 1
class Foo():
f: Callable[[int], int]
def m(self):
print(self.f(1)) # Pyright reports f has Callable[[], int]
foo = Foo()
foo.f = add1 # same here
foo.m()
**To Reproduce**
Run ``npx pyright code.py``
**Expected behavior**
Type of ``f`` should be Callable[[int], int], and no errors occur.
**Screenshots or Code**
An error message that Pyright outputs is below.
10:22 - error: Expected 0 positional arguments (reportGeneralTypeIssues)
13:5 - error: Cannot assign member "f" for type "Foo"
Expression of type "(n: int) -> int" cannot be assigned to member "f" of class "Foo"
Function accepts too few parameters; expected 1 but received 0 (reportGeneralTypeIssues)
2 errors, 0 warnings
```
VS Code extension or command-line
Command-line. But it also occurs in VS Code extension.
Thanks for the bug report. The bug was related to a behavior documented in PEP 526 that Pyright wasn't quite following correctly. PEP 526 indicates that a class-scoped variable that is annotated with a type is assumed to be an instance variable unless explicitly annotated with ClassVar. A Callable instance variable is assumed to be pre-bound to its object, so there is no "self" value passed to it. Pyright wasn't marking the variable as an instance variable, so it assumed that it needed to be bound to the object when it was called. Therefore it assumed that a self parameter would be sent to the Callable, hence the "too few parameters" error message.
This will be fixed in the next version of Pyright.
This is addressed in Pyright 1.1.50, which I just published.
Most helpful comment
This is addressed in Pyright 1.1.50, which I just published.