-
-
Notifications
You must be signed in to change notification settings - Fork 25
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
Error importing plugin "classes.contrib.mypy.classes_plugin" cannot import name 'union_items' from 'mypy.types' #481
Comments
Any workaround for this one? I've tried different UPD. Also I'm getting a mypy error when calling the function I'm trying to overload All in all, I wasn't able to make mypy-plugin to work, and it kinda ruins the whole type-safety idea of UPD2. |
Ok, after downgrading python and mypy my problems boiled down to this minimal example: (test_classes) $ mypy --version
mypy 0.971 (compiled: yes)
(test_classes) $ python --version
Python 3.10.6
(test_classes) $ ll #
total 16
-rw-r--r-- 1 *** *** 83B Jul 6 21:22 setup.cfg
-rw-r--r-- 1 *** *** 438B Jul 7 16:50 try_classes.py
(test_classes) $ cat setup.cfg
# In setup.cfg or mypy.ini:
[mypy]
plugins =
classes.contrib.mypy.classes_plugin
(test_classes) $ cat try_classes.py
from classes import typeclass
@typeclass
def to_json(instance) -> str:
"""That's a definition!"""
@to_json.instance(str)
def _to_json_str(instance: str) -> str:
return '"{0}"'.format(instance)
@to_json.instance(None)
def _to_json_none(instance: None) -> str:
return "null"
assert to_json("text") == '"text"'
assert to_json(None) == "null"
reveal_type(to_json)
(test_classes) $ mypy try_classes.py
try_classes.py:22: note: Revealed type is "classes._typeclass._TypeClass[Union[None, builtins.str], def (instance: Any) -> builtins.str, <nothing>, Literal['try_classes.to_json']]"
Success: no issues found in 1 source file
(test_classes) $ touch __init__.py
~/code/python/test_classes
(test_classes) $ mypy try_classes.py
try_classes.py:9: error: Internal error: attempted lookup of unknown name
try_classes.py:14: error: Internal error: attempted lookup of unknown name
try_classes.py:19: error: Argument 1 to "to_json" has incompatible type "str"; expected <nothing>
try_classes.py:20: error: Argument 1 to "to_json" has incompatible type "None"; expected <nothing>
try_classes.py:22: note: Revealed type is "classes._typeclass._TypeClass[<nothing>, def (instance: Any) -> builtins.str, <nothing>, Literal['test_classes.try_classes.to_json']]"
Found 4 errors in 1 file (checked 1 source file) I'm launching on MacOS Ventura 13.4.1. As you see, adding |
any updates on this issue? |
Same problem here, no solution found in documentation, is there any workaround? |
The solution so far to hard pin |
Bug report
What's wrong
I am hitting the error on a clean installation with python3.11 on MacOS.
How is that should be
No errors
System information
python
version:classes
version:mypy
version:The text was updated successfully, but these errors were encountered: