Pylance-release: pylance is not honoring mypy.ini / mypy plugins (algebraic-data-types package's plugin)

Created on 27 Aug 2020  路  4Comments  路  Source: microsoft/pylance-release

Environment data

  • Language Server version: 2020.8.2
  • OS and version: Windows 10
  • Python version (& distribution if applicable, e.g. Anaconda): 3.8.2
  • MyPy version: 0.782

Preface

I am using the adt package, which has a MyPy plugin for extending typechecking.
I have enabled this plugin by editing mypy.ini in my project directory.

When I run mypy manually, I can see that the plugin is working, because code which would produce type errors without the plugin is no longer producing errors when the plugin is enabled.

Expected behaviour

I expect vscode / pylance to honor this mypy.ini and use the ADT plugin when doing type checking, which allows the adt.Case to have type arguments.

Actual behaviour

I am getting errors indicating that the plugin is not being used:

image

Code Snippet / Additional information

First, pip install algebraic-data-types. Then create a mypy.ini with the following contents:

[mypy]
plugins = adt.mypy_plugin

Then create foo.py with the following code:

from adt import Case, adt

@adt
class Foo:
    x: Case[str]

Then run mypy foo.py. If everything is set up correctly, you should get no errors from mypy. Without the plugin, you will get an error like the following:

foo.py:8: error: "Case" expects no type arguments, but 1 given

Then load that file up in vscode with pylance and see that you are still getting an error even when mypy.ini is in place.

fixed in next version

Most helpful comment

This issue has been fixed in version 2020.8.3, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#202083-28-august-2020

All 4 comments

Mypy plugins are very specific to mypy and its implementation. They do not work with other static type checkers.

Pyright (the static type checker that Pylance is built on) supports all of the Python type standards (e.g. PEP 484, 526, 544), but there are some libraries with non-standard or dynamic behaviors that cannot be described using standard type annotations.

If you would like to run mypy instead of Pylance, the Python extension supports mypy as a linter. See here for instructions.

@erictraut I had no idea that pylance implemented its own type checking!

Is there a way I can use mypy for type checking but pylance for the rest of my linting?

Pylance is both a language server (providing features like completion suggestions and call signature assistance) and a type checker. By default, most of the type-checking diagnostics are disabled because they are of interest only to a subset of Pylance users and can produce false positives for code bases that are not written with type checking in mind. To enable type checking in Pylance, set "python.analysis.typeCheckingMode" to "basic". By default, it is set to "off".

Some diagnostics are reported even if "python.analysis.typeCheckingMode" is set to "off". The one you are seeing ("Expected no type arguments") is an example of this. I think it's reasonable for it to be suppressed when type checking is off, so I'll make that change.

This issue has been fixed in version 2020.8.3, which we've just released. You can find the changelog here: https://github.com/microsoft/pylance-release/blob/master/CHANGELOG.md#202083-28-august-2020

Was this page helpful?
0 / 5 - 0 ratings