python / python/typing

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

オープン
#1,337 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

topic: feature
主要言語
Python
スター
1.8k
フォーク
302
平均マージ
23時間
マージ済み PR(30日)
8

説明

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.

コントリビューションガイド

このリポジトリのコントリビューションガイドは索引されていません

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

Issue自体が入口です。まず、提案されているTYPE_CHECKER辞書、そのnameフィールドとversionフィールド、オプション値、空のランタイム動作を確認します。型チェッカーが一貫したバージョン情報を提供する方法を明確にし、その後、合意したインターフェースを定義して検証します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
tooling
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。