Microsoft has released a new language server for Python called Pylance, which uses the Language Server Protocol to communicate with Microsoft's popular open-source, cross-platform code editor, Visual Studio Code (VS Code).
Pylance, now available as an extension on the Visual Studio Marketplace, delivers a "drastic improvement for the Python experience in Visual Studio Code", according to Savannah Ostrowski, program manager for Python Language Server and Python in Visual Studio.
Pylance could benefit a lot of Python developers given that Microsoft's Python extension for VS Code is by far the most popular language extension on Microsoft's marketplace.
SEE: Hiring Kit: Python developer (TechRepublic Premium)
Pylance is based on Microsoft's Pyright static type-checking tool for Python, which it released last year to help developers quickly clean up and auto-complete code snippets.
"Pyright's type-checking functionality and language features are now incorporated into a VS Code extension called Pylance, the officially supported Python Language Server from Microsoft," Microsoft says in its Pyright page on GitHub.
"Pylance is designed to work with the Python extension for VS Code. In addition to Pyright's functionality, Pylance adds compatibility with several advanced features including IntelliCode for AI-assisted completions. If you are a VS Code user, we recommend that you uninstall Pyright and instead install Pylance. You will get all the benefits of Pyright and more."
The new GitHub repository for Pylance, which Microsoft is using to gather feedback, says it will drastically improve developer productivity and Python code quality.
"Using Pyright, Pylance has the ability to supercharge your Python IntelliSense experience with rich type information, helping you write better code faster," Microsoft says.
Microsoft warns against installing Pyright and Pylance together because that will result in duplicate errors, hover text, and suggested code completions. There are differences between the two, though.
"Pylance leverages Pyright's functionality with additional features, some of which are not open-sourced," Microsoft states in an FAQ.
Also, Pyright is now an officially supported Microsoft type checker for Python. Microsoft intends to develop and maintain it as an open-source project under an MIT license. However, the Pyright extension for VS Code isn't guaranteed to be fully functional or maintained in the long term.
Pylance builds on the 2018 release of the Python Language Server, which brought Python IntelliSense to VS Code.
Pylance's key features include type information, auto-import suggestions, and type-checking diagnostics.
Users can set Pylance's type-checking mode at python.analysis.typeCheckingMode to 'basic' or 'strict'.
"This setting uses Pyright's type checking to apply either a basic or comprehensive set of rules over your codebase, respectively. The diagnostics produced from this mode can help improve the quality of your code and help you find edge cases more easily," said Ostrowski.