Using `classmethod` of generic alias of a generic type and `--disallow-any-generics`
オープン
まだ誰も着手していません。
topic-inference
topic-type-alias
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Code:
from typing import TypeVar, Generic, reveal_type
T = TypeVar('T')
N = TypeVar('N')
class My(Generic[T]):
def __init__(self, arg: T) -> None:
self.arg = arg
@classmethod
def from_arg(cls, arg: N) -> 'My[N]':
return My(arg)
Alias = My[T]
reveal_type(My.from_arg(1))
# note: Revealed type is "__main__.My[builtins.int]"
reveal_type(Alias.from_arg(1))
# error: Missing type parameters for generic type "Alias" [type-arg]
# note: Revealed type is "__main__.My[builtins.int]"
Problem: I think that [type-arg] error should not be raised in this case, because no type param is actually needed in this case. classmethod is often used as a constructor, duplicating type vars is verbose and unneeded.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、リンクされた mypy-play のケースで --disallow-any-generics を使って例を再現し、次にジェネリックエイリアスと classmethod 呼び出しがどのように解析されるかを追跡します。Alias.from_arg(1) が type-arg エラーを発生させなくなり、表示される型が My[int] のままであれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100