coady / multimethod

Multiple argument dispatching.
https://coady.github.io/multimethod
Other
284 stars 23 forks source link

Not work Callable[] #66

Closed Valentin-Miroshnichenko closed 2 years ago

Valentin-Miroshnichenko commented 2 years ago

Hello. I am trying to use Callable in my code. But I get the error multimethod.DispatchError: ('from_producer: 0 methods found', (<class 'function'>,), []) .

What am I doing wrong?

from typing import Callable

from multimethod import multimethod

class AAA():
    @staticmethod
    @multimethod
    def from_producer(producer: Callable[..., int]) -> None:
        q = 1

    @staticmethod
    @multimethod
    def from_producer(producer: int) -> None:
        q = 1

def qwerty() -> int:
    return 1

def test_1():
    AAA.from_producer(qwerty)
coady commented 2 years ago

One problem is that staticmethod has to be applied last (once).

class AAA():
    @multimethod
    def from_producer(producer: Callable[..., int]) -> None:
        q = 1

    @staticmethod
    @multimethod
    def from_producer(producer: int) -> None:
        q = 1

And then 857e4e9 has as additional fix for an infinite recursion problem.