Closed ivanovmg closed 3 years ago
Consider the following script.
from typing import Sequence, Union from multimethod import multimethod @multimethod def func(x: Union[int, Sequence[int]]) -> Sequence[int]: raise NotImplementedError @func.register def _from_int(x: int) -> Sequence[int]: return [x, x] @func.register def _from_sequence(x: Sequence[int]) -> Sequence[int]: return x func(1) func([1, 2])
When executing python script.py I noticed weird behavior.
python script.py
func(1)
func([1, 2])
Traceback (most recent call last): File "script.py", line 22, in <module> func([1, 2]) File "C:\venv\lib\site-packages\multimethod\__init__.py", line 301, in __call__ func = self[tuple(func(arg) for func, arg in zip(self.type_checkers, args))] File "C:\venv\lib\site-packages\multimethod\__init__.py", line 295, in __missing__ raise DispatchError(msg, types, keys) multimethod.DispatchError: ('func: 0 methods found', (<class 'list'>,), [])
I would like to emphasize that this behavior is flaky. Sometimes this error is raised, but sometimes the code executes just fine.
$ pip list Package Version ----------- ------- multimethod 1.6 pip 19.2.3 setuptools 41.2.0
$ python --version Python 3.8.3
In the previous version of multimethod there was no such issue.
Not sure why it would be intermittent; it does look like a bug with new type checker.
Fixed in fd95a14.
Consider the following script.
When executing
python script.py
I noticed weird behavior.func(1)
call works fine.func([1, 2])
either executes fine, or fails with the following errorI would like to emphasize that this behavior is flaky. Sometimes this error is raised, but sometimes the code executes just fine.
In the previous version of multimethod there was no such issue.