News

VS Code Python Type Checker Is Microsoft 'Side Project'

A new open source VS Code extension called Pyright has been created as a Microsoft "side project" to improve on current offerings for static type checking for the Python programming language.

Deemed a work in progress with no official support from Microsoft and much functionality yet to be implemented, the GitHub-based project is described as an attempt to improve on currently available Python type checkers, with mypy mentioned specifically.

Of course, the increasingly popular Visual Studio Code editor already sports an increasingly popular Microsoft-backed, jack-of-all-trades Python extension (just updated) that boasts more than 35 million downloads and 7.3 million installations and does type checking and a whole lot more.

But Pyright isn't aiming to compete with that tool, rather to just improve on its type-checking capabilities, which are powered by the Microsoft Python Language Server that uses the language server protocol to provide IntelliSense and other advanced functionality for different programming languages in code editors and IDEs.

"Pyright provides overlapping functionality but includes some unique features such as more configurability, command-line execution, and better performance," the GitHub project says.

The project -- written in TypeScript -- comes with a command-line tool (CLI) and a VS Code Language Server Protocol plug-in, which provides language service features including:

  • Hover tool tips that display type information
  • Links to symbol definitions
  • Smart priority queuing for interactive feedback during editing

Beyond the language service features, type-checking features currently supported include:

  • PEP 484 type hints including generics (PEP stands for Python Enhancement Proposal)
  • PEP 526 syntax for variable annotations
  • PEP 544 structural subtyping
  • Type inference for function return values, instance variables, class variables, and globals
  • Smart type constraints that understand conditional code flow constructs like if/else statements

Beyond that, there's a whole laundry list of functionality to be implemented, with the project welcoming community contributions to help with:

  • Add enforcement of covariance and contravariance
  • Type inference for generators and async functions
  • Add support for inference of subclass type vars based on method parameter types declared in subclass
  • Validate consistency of subclass type vars across all declared methods
  • Report errors for non-quoted forward references of types
  • Support for old-style type annotations within comments
  • Address the many TODO comments in the code
  • Better handling of function decorators (don't punt on type checking)
  • Add lots of tests
  • Add support for type completion in VS Code extension
  • Special-casing @abstract methods so they don't need to return the specified type
  • Validate that all @abstractmethod are overridden
  • Validate parameters for magic functions
  • Validate that overridden methods in subclass have same signature as base class methods
  • Verify that exception classes inherit from base Exception
  • Validate await/async consistency
  • Flag assignments to read-only values (None, True, False, debug) as errors
  • Revamp support for properties - model with Descriptor protocol, detect missing setter
  • Add numeric codes to diagnostics and a configuration mechanism for disabling errors by code
  • Move error strings out of the main code files so they can be localized

"Pyright is a work in progress," says the GitHub site, which shows seven contributors, led by Microsoft's Eric Traut.

About the Author

David Ramel is an editor and writer for Converge360.

comments powered by Disqus

Featured

Subscribe on YouTube