rcarriga / vim-ultest

The ultimate testing plugin for (Neo)Vim

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ImportError when looking for Literal or Protocol in Python 3.7 typing

spigot opened this issue · comments

error caught in notification handler 'b'/home/michael/.local/share/nvim/site/plugged/vim-ultest/rplugin/python3/ultest:function:_ultest_update_positions' [[b'nvim/.config/nvim/init_plug.vim']]'
Traceback (most recent call last):
  File "/home/michael/.local/lib/python3.7/site-packages/pynvim/plugin/host.py", line 145, in _on_notification
    handler(*args)
  File "/home/michael/.local/lib/python3.7/site-packages/pynvim/plugin/host.py", line 89, in _wrap_delayed_function
    self._discover_functions(plugin, module_handlers, path, False)
  File "/home/michael/.local/lib/python3.7/site-packages/pynvim/plugin/host.py", line 220, in _discover_functions
    for _, fn in inspect.getmembers(obj, predicate):
  File "/usr/lib/python3.7/inspect.py", line 341, in getmembers
    value = getattr(object, key)
  File "/home/michael/.local/share/nvim/site/plugged/vim-ultest/rplugin/python3/ultest/__init__.py", line 76, in handler
    from .handler import HandlerFactory
  File "/home/michael/.local/share/nvim/site/plugged/vim-ultest/rplugin/python3/ultest/handler/__init__.py", line 8, in <module>
    from ..models import File, Namespace, Position, Result, Test, Tree
  File "/home/michael/.local/share/nvim/site/plugged/vim-ultest/rplugin/python3/ultest/models/__init__.py", line 3, in <module>
    from .file import File
  File "/home/michael/.local/share/nvim/site/plugged/vim-ultest/rplugin/python3/ultest/models/file.py", line 2, in <module>
    from typing import List, Literal
ImportError: cannot import name 'Literal' from 'typing' (/usr/lib/python3.7/typing.py)

Describe the bug
Literal and Protocol weren't added to typing until 3.8

To Reproduce
install vim-ultest on a system with Python 3.7

Additional context
vim-ultest/rplugin/python3/ultest/models/file.py
vim-ultest/rplugin/python3/ultest/models/namespace.py
vim-ultest/rplugin/python3/ultest/models/tree.py
vim-ultest/rplugin/python3/ultest/models/tree.py
all attempt to import either Literal or Protocol from typing. both were added in 3.8. you can find them in typing_extensions, though. so this code replacing the import (for Literal or Protocol where appropriate) in those files seems to work after typing_extensions is installed via pip

try:
    from typing import Literal
except ImportError:
    from typing_extensions import Literal

Thanks for the report! These types are only needed for development so users shouldn't need to install a third party dependency for them. I've added fallback classes as a fix instead.