Skip to content

Can not pass generic function to generic function #1208

@sharkdp

Description

@sharkdp

The following example …

from typing import Callable

def invoke[A, B](fn: Callable[[A], B], value: A) -> B:
    return fn(value)

def identity[T](x: T) -> T:
    return x

invoke(identity, 1)

(https://play.ty.dev/6dfb9951-b78f-4791-af82-151a1c694a7c)

… currently fails with this error:

error[invalid-argument-type]: Argument to function `invoke` is incorrect
  --> /home/shark/playground/test.py:12:8
   |
12 | invoke(identity, 1)
   |        ^^^^^^^^ Expected `(Literal[1], /) -> Unknown`, found `def identity[T](x: T@identity) -> T@identity`
   |
info: Function defined here
 --> /home/shark/playground/test.py:4:5
  |
4 | def invoke[A, B](fn: Callable[[A], B], value: A) -> B:
  |     ^^^^^^       -------------------- Parameter declared here
5 |     return fn(value)
  |
info: rule `invalid-argument-type` is enabled by default

I am reporting this in addition to #623, because it seems like this is not really related to the shortcomings of the current solver, but rather to the way we handle assignability of the generic identity function argument to the call(?).

Metadata

Metadata

Assignees

Labels

bugSomething isn't workinggenericsBugs or features relating to ty's generics implementation

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions