pfun icon indicating copy to clipboard operation
pfun copied to clipboard

Support decoratoring methods with curry in the MyPy plugin

Open suned opened this issue 4 years ago • 0 comments

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())

suned avatar Jun 15 '21 09:06 suned