multimethod icon indicating copy to clipboard operation
multimethod copied to clipboard

Not work Callable[]

Open Valentin-Miroshnichenko opened this issue 3 years ago • 1 comments

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)

Valentin-Miroshnichenko avatar May 13 '22 15:05 Valentin-Miroshnichenko

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.

coady avatar May 14 '22 15:05 coady