python / python/mypy

Better message for "Function ... could always be true"

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

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

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

説明

Consider this example:

def f(x: int) -> str: pass

if f:
    pass

It generates this error:

t.py:3: error: Function "Callable[[int], str]" could always be true in boolean context  [truthy-function]

Instead, if we have a direct reference to a function definition, we could generate a message like this which would be clearer, especially if the signature is complex:

t.py:3: error: Function "f" could always be true in boolean context  [truthy-function]

There are at least these different cases to consider:

  1. Direct reference to a function using a short name of a function (similar to the above example).
  2. Direct reference to a function using a module prefix (e.g. if mod.func:).
  3. Reference to a method (e.g. if obj.method:).
  4. Reference to a variable/attribute (Var node) with type Callable[...] (in this case we could show the name of the variable/attribute or the callable type -- both would be okay).
  5. Any other expression that produces a callable value, such as if func(): where func returns a callable. Here the best option is to show the callable type as we do now.

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

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

はじめの一歩

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

調査の方向性

まず例を再現し、[truthy-function] 診断が呼び出し可能な式をどのようにフォーマットするかを調べます。関数への直接参照、モジュール修飾された関数、メソッド、呼び出し可能な変数または属性、呼び出し可能なオブジェクトを返す式を比較します。直接参照では適切な場合に、より分かりやすい関数名が使われ、それ以外の場合では有用な呼び出し可能オブジェクトの型または式の説明が維持されれば完了です。

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

評価

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

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

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