python / python/mypy

`UNBOUND_TYPEVAR` error message should be more direct and shorter

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

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

bug
主要言語
Python
スター
20.6k
フォーク
3.3k
PR マージ指標
PR 指標を取得中

説明

*Notes:

The last 3 examples get the same indirect and long error messages of UNBOUND_TYPEVAR as shown below:

*Notes:

  • A parameter is a variable defined in a function header to receive an argument.
  • An argument is a value passed to a function parameter.

A function returning TypeVar should receive at least one argument containing the same TypeVar

With T for x:
def func[T](x: T) -> T:
    return x
# No error
Without T for x:
def func[T](x) -> T:
    return x
# error: A function returning TypeVar should receive at least one argument containing the same TypeVar
With no parameters:
from typing import cast

def func[T]() -> T:
    return cast(T, 'Hello')
# error: A function returning TypeVar should receive at least one argument containing the same TypeVar
With T1 for x and T2 for return type:
def func[T1, T2](x: T1) -> T2:
    return x
# error: A function returning TypeVar should receive at least one argument containing the same TypeVar

So, the same indirect and long error messages of UNBOUND_TYPEVAR should be changed:

From:

A function returning TypeVar should receive at least one argument containing the same TypeVar

To more direct and shorter one below:

A function returning TypeVar should have at least one same TypeVar parameter

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

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

はじめの一歩

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

調査の方向性

mypy test.py の例から始めて、UNBOUND_TYPEVAR 診断がどこで生成され、テストされているかを特定します。メッセージを要求された短い文言に更新し、その後、3 つの失敗する例が新しい診断を出力し、有効な例は変更されていないことを確認します。

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

評価

技術スタック
python
領域
devtools
issue の種類
バグ
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
45/100

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

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