Skip to content

Type relations for function-like callables are too strict #1342

@sharkdp

Description

@sharkdp

Assignability, subtyping, and maybe also equivalence are currently too strict for function-like callables. For example, it should be possible to assign Mock() to a function-like callable, but we currently get:

from dataclasses import dataclass
from unittest.mock import Mock

@dataclass(order=True)
class Data:
    value: int

def test_t():
    d = Data(1)
    # error: Object of type `Mock` is not assignable to
    # attribute `__lt__` of type `(self: Data, other: Data) -> bool`
    d.__lt__ = Mock()

https://play.ty.dev/8148ed96-48fa-4706-9e50-2ff61f0f5a05

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcallsIssues relating to call-signature checking and diagnostics

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions