question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Real-time mypy linting disabled when using a plugin

See original GitHub issue

Environment data

VSCode Version: 1.36.1 OS Version: macOS 10.14.5 Python version : 3.7.2 Type of virtual environment used : pyenv viapipenv Relevant/affected Python packages and their versions: N/A Jedi or Language Server? (i.e. what is “python.jediEnabled”): Language Server ("python.jediEnabled": false)

Expected behaviour

When mypy linting is enabled, VSCode should use the mypy.ini and accordingly adopt any plugins that are used and installed, and display real-time warnings/errors in the editor.

Actual behaviour

When a plugin is used, all real-time checking is disabled.

Steps to reproduce:

  1. Enable Python and mypy linting in settings.
  2. You will see errors (red squiggly line) if you define a function like this one:
def some_func() -> int:
    return "some string"
  1. Install a mypy specific plugin. In my case it was django-stubs:
"python.linting.mypyEnabled": true,
    "python.linting.mypyArgs": [
        "--config-file=${workspaceFolder}/mypy.ini"
    ],

and the mypy.ini file contents:

[mypy]
plugins = mypy_django_plugin.main


warn_unused_ignores = True
strict_optional = True
check_untyped_defs = True
follow_imports = silent
ignore_missing_imports = True
show_column_numbers = True

[mypy.plugins.django-stubs]
django_settings_module = my_app.settings.dev

When I run mypy like so:

PYTHONPATH=${PYTHONPATH}:${PWD} mypy core/selectors.py

I get the correct errors, for example:

error: Incompatible return value type (got “int”, expected “Iterable[SomeModel]”)

But this is not highlighted in my editor in real-time/after save.

However, if I remove the plugin section from the mypy.ini file, I do get an error in the editor:

Incompatible return value type (got “int”, expected “Iterable[SomeModel]”) mypy(error)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:1
  • Comments:9

github_iconTop GitHub Comments

1reaction
karrtikrcommented, Aug 21, 2019

Thanks for cooperating. As I am not able to reproduce this, I would’ve to ask you to try few things.

  • ~/.virtualenvs/myvirtualenv/bin/python -m mypy --config-file=/Users/myusername/Projects/project_root/mypy.ini ~/Projects/project_root/accounts/models.py

Try running this command in the terminal. I expect to see error Error constructing plugin instance of NewSemanalDjangoPlugin.

  • Now try initializing PYTHONPATH variable followed by the command
$ PYTHONPATH=${PYTHONPATH}:${PWD}

$ ~/.virtualenvs/myvirtualenv/bin/python -m mypy --config-file=/Users/myusername/Projects/project_root/mypy.ini ~/Projects/project_root/accounts/models.py

If the second one works, it means extension is not initializing the PYTHONPATH environment variable like it should.

Also, could you try a different interpreter and see if it reproduces the issue?

0reactions
karrtikrcommented, Aug 22, 2019

Try to choose a different Python version interpreter, with mypy installed. Maybe one without virtualenv.

python.pythonPath setting gets set when you choose a python interpreter.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Mypy and PyLint real-time (and on-demand) code inspection ...
Mypy and PyLint real-time (and on-demand) code inspection from within PyCharm/IDEA. These two plugins provide real-time and on-demand code ...
Read more >
emacs-lsp/lsp-mode - Gitter
So, it appears that in order for mypy to work with pyls , a special package needs installing. If you've got a package...
Read more >
Common issues and solutions - mypy 0.991 documentation
Common issues and solutions#. This section has examples of cases when you need to update your code to use static typing, and ideas...
Read more >
Flake8-mypy: A Plugin for Flake8 integrating Mypy - Morioh
The Flake8 plugin traded correctness for performance, making Mypy only check a bare ... lint-style cleanliness for typing needs to be disabled; returns...
Read more >
mypy in vscode consumes too much memory - Stack Overflow
recently I observed VScode is using an insane amount of memory and ... The issue will go away only if I turned off...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found