Closed
Description
Small example to illustrate the issue:
import typing as t
from dataclasses import dataclass, field
@dataclass
class Example:
a: t.Callable[[], int] = field(default=lambda: 42)
def call_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.
from typing import t
from dataclasses import dataclass, field
@dataclass
class Example:
a: t.Callable[['Example'], int] = field(default=lambda: 42) # Incompatible types in assignment (expression has type "Callable[[], int]", variable has type "Callable[[Example], int]")
def call_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