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

  • Microsoft Revamps Fledgling AutoGen Framework for Agentic AI

    Only at v0.4, Microsoft's AutoGen framework for agentic AI -- the hottest new trend in AI development -- has already undergone a complete revamp, going to an asynchronous, event-driven architecture.

  • IDE Irony: Coding Errors Cause 'Critical' Vulnerability in Visual Studio

    In a larger-than-normal Patch Tuesday, Microsoft warned of a "critical" vulnerability in Visual Studio that should be fixed immediately if automatic patching isn't enabled, ironically caused by coding errors.

  • Building Blazor Applications

    A trio of Blazor experts will conduct a full-day workshop for devs to learn everything about the tech a a March developer conference in Las Vegas keynoted by Microsoft execs and featuring many Microsoft devs.

  • Gradient Boosting Regression Using C#

    Dr. James McCaffrey from Microsoft Research presents a complete end-to-end demonstration of the gradient boosting regression technique, where the goal is to predict a single numeric value. Compared to existing library implementations of gradient boosting regression, a from-scratch implementation allows much easier customization and integration with other .NET systems.

  • Microsoft Execs to Tackle AI and Cloud in Dev Conference Keynotes

    AI unsurprisingly is all over keynotes that Microsoft execs will helm to kick off the Visual Studio Live! developer conference in Las Vegas, March 10-14, which the company described as "a must-attend event."

Subscribe on YouTube