GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Error importing plugin "classes.contrib.mypy.classes_plugin" cannot import name 'union_items' from 'mypy.types' · Issue #481 · dry-python/classes

Error importing plugin "classes.contrib.mypy.classes_plugin" cannot import name 'union_items' from 'mypy.types' #481

New issue
Copy link
New issue
Copy link
Open
#483
Open
Error importing plugin "classes.contrib.mypy.classes_plugin" cannot import name 'union_items' from 'mypy.types'#481
#483
Copy link
Labels
bugSomething isn't workingSomething isn't working

Description

@zhukovgreen
zhukovgreen
opened on Mar 14, 2023
Issue body actions

Bug report

What's wrong

I am hitting the error on a clean installation with python3.11 on MacOS.

Python 3.11.1 (main, Dec 12 2022, 14:17:59) [Clang 14.0.0 (clang-1400.0.29.202)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import classes.contrib.mypy.classes_plugin
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/uname/PycharmProjects/sandbox/.venv/lib/python3.11/site-packages/classes/contrib/mypy/classes_plugin.py", line 33, in <module>
    from classes.contrib.mypy.features import associated_type, supports, typeclass
  File "/Users/uname/PycharmProjects/sandbox/.venv/lib/python3.11/site-packages/classes/contrib/mypy/features/typeclass.py", line 17, in <module>
    from classes.contrib.mypy.typeops import (
  File "/Users/uname/PycharmProjects/sandbox/.venv/lib/python3.11/site-packages/classes/contrib/mypy/typeops/call_signatures.py", line 9, in <module>
    from mypy.types import TypeVarType, union_items
ImportError: cannot import name 'union_items' from 'mypy.types' (/Users/uname/PycharmProjects/sandbox/.venv/lib/python3.11/site-packages/mypy/types.cpython-311-darwin.so)

How is that should be

No errors

System information

  • python version:
  • classes version:
  • mypy version:
Reacted by Steve Phelps, Dmitrii Altukhov, Berserk and MikBark

Activity

  1. zhukovgreen
    added
    bugSomething isn't workingSomething isn't working
    on Mar 14, 2023
  2. zhukovgreen
    added a commit that references this issue on Mar 16, 2023

    Pin mypy version to ensure correct work of the mypy plugin

    4050e2a
  3. dmalt commented on Jul 6, 2023

    @dmalt
    dmalt
    on Jul 6, 2023
    More actions

    Any workaround for this one? I've tried different mypy versions but mypy-plugin doesn't want to work with any of them.

    UPD.
    The plugin does seem to work for mypy version < 0.981 and python < 3.10.7, but mypy this old stops to recognise phantom types. It throws Internal 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 classes for me. Maybe I'm missing something?

    UPD2.
    That's weird but mypy-plugin starts to work as expected as soon as I remove __init__.py from my package.

  4. dmalt commented on Jul 7, 2023

    @dmalt
    dmalt
    on Jul 7, 2023
    More actions

    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__.py breaks the typechecking.

    Reacted by zhukovgreen
  5. eineruntervielen commented on Sep 25, 2023

    @eineruntervielen
    eineruntervielen
    on Sep 25, 2023
    More actions

    any updates on this issue?

    Reacted by Jellyfish.tech
  6. jellyfish-tech commented on Nov 1, 2023

    @jellyfish-tech
    jellyfish-tech
    on Nov 1, 2023
    More actions

    Same problem here, no solution found in documentation, is there any workaround?

  7. zhukovgreen commented on Apr 5, 2024

    @zhukovgreen
    zhukovgreen
    on Apr 5, 2024
    Author
    More actions

    The solution so far to hard pin mypy==0.971

    Reacted by Berserk
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402503 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.