mypy does not recognize tuple unpacking syntax for TypeVars.
オープン
まだ誰も着手していません。
feature
priority-2-low
topic-runtime-semantics
topic-type-variables
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Bug Report
This is really a minor issue, but if you declare multiple TypeVar variables in one line, mypy does not seem to recognize them as type variables. For example,
from typing import TypeVar, Generic
T1, T2 = TypeVar('T1'), TypeVar('T2')
class Container(Generic[T1]):
class Item(Generic[T2]):
pass
To Reproduce
- Declare more than one TypeVars in one line. (See the example code above.)
- Run mypy check on this script.
Expected Behavior
The T1 and T2 in the example above should be recognized as type variables.
They should pass mypy check.
Actual Behavior
Errors:
$ mypy typevar.py
typevar.py:5: error: Free type variable expected in Generic[...]
typevar.py:6: error: Free type variable expected in Generic[...]
Found 2 errors in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 0.910
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.10.0
- Operating system and version: Ubuntu 20.04
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
提供された Python スニペットと mypy typevar.py コマンドで問題を再現し、その後、Generic[...] を確認する前にタプル代入された TypeVars がどのように認識されるかを追跡します。T1 と T2 の両方が型変数として受け入れられ、例がエラーなしで mypy を通過すれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100