coady / multimethod

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

importing multimethod #123

Closed Wouter1 closed 3 weeks ago

Wouter1 commented 3 weeks ago

Describe the bug

Python 3.8.10

I do inside a venv

pip list
multimethod       1.10

and then in python, import fails:

>>> from multimethod import multimethod
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/tmp/PythonVenvs/geniusweb1targz/lib/python3.8/site-packages/multimethod/__init__.py", line 8, in <module>
    from typing import Any, Callable, Dict, Iterable, Iterator, Literal, Mapping, Optional, Tuple
  File "/tmp/PythonVenvs/geniusweb1targz/lib/python3.8/site-packages/plum/typing.py", line 10, in <module>
    import typing_extensions
  File "/tmp/PythonVenvs/geniusweb1targz/lib/python3.8/site-packages/typing_extensions.py", line 166, in <module>
    NoReturn = typing.NoReturn
AttributeError: partially initialized module 'typing' has no attribute 'NoReturn' (most likely due to a circular import)

To Reproduce

from multimethod import multimethod

Expected behavior succesfull import

Wouter1 commented 3 weeks ago

For the test above I used a venv that was already on my machine.

I found that it works OK if I use a completely empty venv and only install multimethod.

So the issue I reported must be a result of a conflict between multimethod and another installed library

Let me know if you want to dig deeper.

Wouter1 commented 3 weeks ago

The full pip list was this for my failed test

z$ pip list
Package           Version
----------------- -------
beartype          0.18.5
geniusweb         1
logging           1.1.0
markdown-it-py    3.0.0
mdurl             0.1.2
mockito           1.4.0
multimethod       1.10
pip               24.2
pkg_resources     0.0.0
plum-dispatch     2.4.2
psutil            6.0.0
Pygments          2.18.0
PyHamcrest        2.0.4
pyson             1.2.0
pythonlangutil    0.1
rich              13.8.0
setuptools        44.0.0
typing_extensions 4.12.2
unitpy            1.1.0
uri               2.0.0
utilities         1.0.7
Wouter1 commented 3 weeks ago

I found that plum is the conflicting library. plum is another multi-dispatch library. It uses a different annotation @dispatch instead of @multimethod. After removing that from my venv, multimethod worked OK.

coady commented 3 weeks ago

I found that plum is the conflicting library. plum is another multi-dispatch library. It uses a different annotation @dispatch instead of @multimethod. After removing that from my venv, multimethod worked OK.

Besides being installed, plum must have been on the path. typing is built-in, but it was finding plum's first.

  File "/tmp/PythonVenvs/geniusweb1targz/lib/python3.8/site-packages/multimethod/__init__.py", line 8, in <module>
    from typing import Any, Callable, Dict, Iterable, Iterator, Literal, Mapping, Optional, Tuple
  File "/tmp/PythonVenvs/geniusweb1targz/lib/python3.8/site-packages/plum/typing.py", line 10, in <module>
    import typing_extensions