python / python/typing

`typing.TYPE_CHECKER` object to change types depending on which type checker is being run

Open
#1,337 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

topic: feature
Dominant language
Python
Stars
1.8k
Forks
302
Avg merge
23h
Merged PRs (30d)
8

Description

One issue I have run into as a library dev is varying support for typing features or bugs for both of the type checkers. typing.TYPE_CHECKER would allow me to change type definition based on the type checker so that I can support all static analysis tools more effectively.

I propose that TYPE_CHECKER would be a dict with a "name" and "version" key. Type checkers could also optionally add other keys/values.

TYPE_CHECKER = {
    "name": "type-checker-name",
    # `VersionInfo` would be implemented by each type checker to match their versioning scheme.
    "version": VersionInfo(...),
}

Using it for types would look like this:

if TYPE_CHECKER.get("name") == "pyright" and TYPE_CHECKER.get("version") > (1, 1, 290):
    T = TypeVar("T", default=int)
else:
    T = TypeVar("T")

At runtime I think the TYPE_CHECKER object should be an empty dictionary.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

The issue itself is the entry point: start by reviewing the proposed TYPE_CHECKER dictionary, its name and version fields, optional values, and empty runtime behavior. Resolve how type checkers would provide consistent version information, then define and validate the agreed interface.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.