Skip to content

Frozen dataclass with function fields incorrectly thinks first argument is self #10711

Closed
@wrobell

Description

@wrobell

Example from #5485 works with mypy 0.902

from dataclasses import dataclass
from typing import Callable

@dataclass
class Repro:
    fn: Callable[[int], str]

r = Repro(fn=repr)
assert "1" == r.fn(1)

but let's change the dataclass to a frozen one

from dataclasses import dataclass
from typing import Callable

@dataclass(frozen=True)
class Repro:
    fn: Callable[[int], str]

r = Repro(fn=repr)
assert "1" == r.fn(1)

then

$ mypy t.py
t.py:9: error: Invalid self argument "Repro" to attribute function "fn" with type "Callable[[int], str]"
t.py:9: error: "str" not callable
Found 2 errors in 1 file (checked 1 source file)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions