tomv564 / pyls-mypy

Mypy plugin for the Python Language Server
MIT License
110 stars 62 forks source link

Cannot perform relative import #36

Closed bbc2 closed 4 years ago

bbc2 commented 4 years ago

Some relative imports cause errors. Here's an example:

Directory structure:

foo/
├── bar.py
├── baz.py
└── __init__.py

bar.py:

a = 17

baz.py:

from . import bar

a = bar.a

Runtime test:

> python
Python 3.8.0 (default, Oct 23 2019, 18:51:26) 
[GCC 9.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import foo.baz
>>> foo.baz.a
17

Mypy test:

> mypy foo
Success: no issues found in 3 source files

But when pyls-mypy is installed, the language server complains about the relative import in baz.py:

No parent module -- cannot perform relative import

If I uninstall this extension, the error disappears and the rest of the language server works as expected but without Mypy messages.

tomv564 commented 4 years ago

This can probably be fixed by turning live_mode setting off (see example config in readme) - the as-you-type checker doesn't know where a given chunk of code lives in the filesystem.

bbc2 commented 4 years ago

Ah, that seems fair. Turning off live mode indeed fixes the issue.

tomv564 commented 4 years ago

Thanks for confirming! I'm curious if using the mypy daemon will fix it.