简体   繁体   中英

Difference between mypy vs mypy-lang vs pyls-mypy python packages

I am exploring static type checker for Python and came across different packages while setting up Visual Studio Code. I have installed python-language-server for linting and formatting. I came across mypy.exe and mypyls.exe executables.

I could do,

pip install mypy

pip install mypy-lang

pip install pyls-mypy

All the above three works. But,

  1. I would like to know the difference between mypy , mypy-lang and pyls-mypy packages?
  2. Which of these is used for enabling the Type-Checker (or all the 3 are needed)?
  3. Are these packages in any way related to the python-language-server ? If yes, how ?

I would like to know the difference between mypy, mypy-lang and pyls-mypy packages?

The mypy package contains the mypy type checker, which is what performs all of the actual code analysis, type inference, and type checking.

The mypy-lang package is a deprecated one. If you install it/try using it, I believe all it will do is tell you should be installing the mypy package instead (though I'm not sure how visible this note actually is).

Basically, it turned out that when mypy was first created, somebody had already grabbed the "mypy" name on pypi for an unrelated project, so the mypy devs settled for "mypy-lang" instead.

But after a few years/few unsuccessful attempts to contact the owner of the "mypy" package, it became clear that package was abandoned, so ownership was transferred to the mypy devs.

The pyls-mypy package is an independent project that basically implements a Python language server that understands type hints.

The " language server protocol " is a protocol that's steadily growing in popularity that tries to make it easier to add better tooling for programming languages to IDEs.

The idea is that if you own a programming language or some linter, you don't want to write N different plugins for N different editors. Instead, you implement this protocol just once, and any IDEs and editors that support LSP will then automatically understand your tool.

The reason why installing pyls-mypy "just works" is probably because it declares mypy as a dependency .

Which of these is used for enabling the Type-Checker (or all the 3 are needed)?

Only the mypy package is needed for type checking.

However, mypy itself can only be invoked from the command line. If you want to integrate it with some other editor or IDE, you'll need to install some extra tools.

For example, if you want to use mypy from directly within PyCharm, you'd need to install a mypy/Pycharm plugin .

As another example, if you want to use mypy from some editor that supports LSP, you'll need to install something like pyls-mypy.

Are these packages in any way related to the python-language-server ? If yes, how ?

pyls-mypy is apparently a plugin for/builds on top of Palantir's python-language-server project. See the project readme and their requirements.txt file.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM