python / python/mypy

Improve mypy --pretty output for (multiline) f-strings

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

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

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

説明

Error messages merely say the line number, which is not always accurate - e.g. for multiline strings it's merely the first or last line of the overall multiline string (depending on Python version). If it's a format string and there's dozens of {} elements embedded in it, maybe across hundreds of lines, it can be practically impossible to tell what mypy is referring to. e.g. here's the actual output from a current problem:

     src.py:136: error: "str" has no attribute "expression"  [attr-defined]
     src.py:136: error: Item "str" of "Optional[str]" has no attribute "expression"  [union-attr]
     src.py:136: error: Item "None" of "Optional[str]" has no attribute "expression"  [union-attr]
     src.py:136: error: Item "float" of "Optional[float]" has no attribute "expression"  [union-attr]
     src.py:136: error: Item "None" of "Optional[float]" has no attribute "expression"  [union-attr]
     src.py:136: error: "float" has no attribute "expression"  [attr-defined]
     src.py:136: error: "bool" has no attribute "expression"  [attr-defined]
     src.py:136: error: "int" has no attribute "expression"  [attr-defined]

The multiline string these are embedded in is nearly a hundred lines long and has dozens of embedded elements, almost all of which reference an espression attribute. I genuinely have no idea which ones these messages are referring to. If it at least told me the name of the variable (or whatever), I'd be able to narrow it down.

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

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

はじめの一歩

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

調査の方向性

まず、複数行の f-strings で発生するエラーについて、mypy の --pretty による診断表示を追跡します。報告された位置を、そのエラーを引き起こした埋め込み式と比較します。pretty 出力が文字列全体の行だけでなく、該当する f-string の式または変数を特定できれば完了です。

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

評価

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

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

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