suned / pfun

Functional, composable, asynchronous, type-safe Python.
https://pfun.dev/
MIT License
151 stars 14 forks source link

Support decoratoring methods with curry in the MyPy plugin #82

Open suned opened 3 years ago

suned commented 3 years ago

Currently, curry instances returned from decorating methods with curry doesn't eliminate the self argument, which issues a type error when trying to call a curried method:

from pfun import curry

class C:
    @curry
    def f(x: int, y: int) -> int: ...

reveal_type(C().f)  #  note: Revealed type is 'pfun.functions.Curry[def (self: test_types.C, x: builtins.int, y: builtins.int) -> builtins.int]'
C().f(1)  # error: Argument 1 to "__call__" of "Curry" has incompatible type "int"; expected "C"

The main issue in fixing this is finding a way to distinguish this call to curry with a call with an instance that has a __call__ method in e.g:

class C:
     def __call__(self, x: int, y: int) -> int: ...

curry(C())