Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flaky performance in version 1.6 for sequences #53

Closed
ivanovmg opened this issue Sep 17, 2021 · 2 comments
Closed

Flaky performance in version 1.6 for sequences #53

ivanovmg opened this issue Sep 17, 2021 · 2 comments

Comments

@ivanovmg
Copy link

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.

  • func(1) call works fine.
  • func([1, 2]) either executes fine, or fails with the following error
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.

@coady
Copy link
Owner

coady commented Sep 18, 2021

Not sure why it would be intermittent; it does look like a bug with new type checker.

@coady
Copy link
Owner

coady commented Sep 18, 2021

Fixed in fd95a14.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants