Repository navigation
Error importing plugin "classes.contrib.mypy.classes_plugin" cannot import name 'union_items' from 'mypy.types' #481
Description
Activity
- added a commit that references this issue
on Mar 16, 2023 Any workaround for this one? I've tried different
mypyversions but mypy-plugin doesn't want to work with any of them.UPD.
The plugin does seem to work formypyversion < 0.981 and python < 3.10.7, but mypy this old stops to recognise phantom types. It throwsInternal error: attempted lookup of unknown name [misc]for phantom types at me.Also I'm getting a mypy error when calling the function I'm trying to overload
Argument 1 to "read" has incompatible type "Path"; expected <nothing>All in all, I wasn't able to make mypy-plugin to work, and it kinda ruins the whole type-safety idea of
classesfor me. Maybe I'm missing something?UPD2.
That's weird butmypy-pluginstarts to work as expected as soon as I remove__init__.pyfrom my package.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
__init__.pybreaks the typechecking.Reacted by zhukovgreenany updates on this issue?
Reacted by Jellyfish.techSame problem here, no solution found in documentation, is there any workaround?
The solution so far to hard pin
mypy==0.971Reacted by Berserk
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
pythonversion:classesversion:mypyversion: