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

  • Creating Business Applications Using Blazor

    Expert Blazor programmer Michael Washington' will present an upcoming developer education session on building high-performance business applications using Blazor, focusing on core concepts, integration with .NET, and best practices for development.

  • GitHub Celebrates Microsoft's 50th by 'Vibe Coding with Copilot'

    GitHub chose Microsoft's 50th anniversary to highlight a bevy of Copilot enhancements that further the practice of "vibe coding," where AI does all the drudgery according to human supervision.

  • AI Coding Assistants Encroach on Copilot's Special GitHub Relationship

    Microsoft had a great thing going when it had GitHub Copilot all to itself in Visual Studio and Visual Studio Code thanks to its ownership of GitHub, but that's eroding.

  • VS Code v1.99 Is All About Copilot Chat AI, Including Agent Mode

    Agent Mode provides an autonomous editing experience where Copilot plans and executes tasks to fulfill requests. It determines relevant files, applies code changes, suggests terminal commands, and iterates to resolve issues, all while keeping users in control to review and confirm actions.

  • Windows Community Toolkit v8.2 Adds Native AOT Support

    Microsoft shipped Windows Community Toolkit v8.2, an incremental update to the open-source collection of helper functions and other resources designed to simplify the development of Windows applications. The main new feature is support for native ahead-of-time (AOT) compilation.

Subscribe on YouTube