Small example to illustrate the issue:
importtypingastfromdataclassesimportdataclass, field@dataclassclassExample:
a: t.Callable[[], int] =field(default=lambda: 42)
defcall_a(self) ->None:
self.a() # Attribute function "a" with type "Callable[[], int]" does not accept self argument
Curiously, adding Example as the first argument to the type of a makes the call be recognized OK but the default not.
fromtypingimporttfromdataclassesimportdataclass, field@dataclassclassExample:
a: t.Callable[['Example'], int] =field(default=lambda: 42) # Incompatible types in assignment (expression has type "Callable[[], int]", variable has type "Callable[[Example], int]")defcall_a(self):
self.a()
Your Environment
- Mypy version used: mypy 0.782
- Mypy command-line flags:
- Mypy configuration options from
mypy.ini (and other config files): - Python version used: 3.7
- Operating system and version: Debian WSL
Small example to illustrate the issue:
Curiously, adding
Exampleas the first argument to the type ofamakes the call be recognized OK but the default not.Your Environment
mypy.ini(and other config files):