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 at Converge 360.

comments powered by Disqus

Featured

  • Compare New GitHub Copilot Free Plan for Visual Studio/VS Code to Paid Plans

    The free plan restricts the number of completions, chat requests and access to AI models, being suitable for occasional users and small projects.

  • Diving Deep into .NET MAUI

    Ever since someone figured out that fiddling bits results in source code, developers have sought one codebase for all types of apps on all platforms, with Microsoft's latest attempt to further that effort being .NET MAUI.

  • Copilot AI Boosts Abound in New VS Code v1.96

    Microsoft improved on its new "Copilot Edit" functionality in the latest release of Visual Studio Code, v1.96, its open-source based code editor that has become the most popular in the world according to many surveys.

  • AdaBoost Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the AdaBoost.R2 algorithm for regression problems (where the goal is to predict a single numeric value). The implementation follows the original source research paper closely, so you can use it as a guide for customization for specific scenarios.

  • Versioning and Documenting ASP.NET Core Services

    Building an API with ASP.NET Core is only half the job. If your API is going to live more than one release cycle, you're going to need to version it. If you have other people building clients for it, you're going to need to document it.

Subscribe on YouTube