Generic argument is not being identified
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Bug Report
The code in this mypy playground raises the following error.
Name "T" is not defined [name-defined]
However, as seen in this pyright playground there is no error, which leads me to believe that the snippet is well defined.
This one is probably related but the revealed types do not seem to match as well (the ? in the type name seems to be rather strange).
mypy
"__main__.Repo[T?, U`-2]"
pyright
"Repo[T@some, U@some]"
To Reproduce (this is the same code as in the mypy playground)
from typing import cast, reveal_type
from collections.abc import Callable
class Repo[T, U]: ...
def some[T, U, **P](func: Callable[P, U]) -> Callable[P, U]:
def wrapper(*args: P.args, **kwargs: P.kwargs) -> U:
reveal_type(cast(Repo[T, U], args[0]))
return func(*args, **kwargs)
return wrapper
Expected Behavior
No errors from mypy, similar behavior to pyright.
Actual Behavior
I am not sure if mypy is misdiagnosing this, if you feel this is intended behavior I can try raising an issue with pyright.
Your Environment
- Mypy version used: 1.15.0 (playground)
- Pyright version used: 1.1.399 (playground)
- Mypy command-line flags: default settings in mypy playground (if I am not mistaken, there are no extra flags)
- Mypy configuration options from
mypy.ini(and other config files): N/A - Python version used: 3.13 (for both playgrounds)
Thank You
Edit: Simplified the example a bit by removing the bounds and awaitables.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされている mypy playground と、「To Reproduce」の下にある最小限の再現例から始め、その結果をリンクされている pyright playground と比較します。wrapper 内および cast(Repo[T, U], args[0]) でジェネリックパラメーター T と U がどのように解決されるかを追跡します。mypy が T を未定義として報告しなくなり、その revealed type が期待されるジェネリック形式と一致すれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 38/100