python / python/mypy

Wrong column reported for errors in function sig type comments

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

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

bug priority-2-low topic-error-reporting topic-usability
主要言語
Python
スター
20.6k
フォーク
3.3k
PR マージ指標
PR 指標を取得中

説明

For the following code



def extract_commit_hash(line):  # type: (str) -> Optional[str]
    ...

def extract_commit_hash2(line):  # type: (str) -> Optional(str)
    ...


mypy reports wrong columns:

image

mypy output:

> mypy --pretty --follow-imports skip --show-column-numbers --show-error-codes wrong-col.py
wrong-col.py:3:10: error: Name 'Optional' is not defined  [name-defined]
    def extract_commit_hash(line):  # type: (str) -> Optional[str]
             ^
wrong-col.py:3:10: note: Did you forget to import it from "typing"? (Suggestion: "from typing import Optional")
wrong-col.py:6:10: error: Invalid type comment or annotation  [valid-type]
    def extract_commit_hash2(line):  # type: (str) -> Optional(str)
             ^
wrong-col.py:6:10: note: Suggestion: use Optional[...] instead of Optional(...)
Found 2 errors in 1 file (checked 1 source file)

From what I found the reported column is always 10 even if the code is more indented.

image

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

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

はじめの一歩

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

調査の方向性

示されている wrong-col.py の例と、--show-column-numbers を使用する mypy コマンドで報告を再現します。関数シグネチャの型コメントに対する診断がどのように列番号を計算するかを追跡し、その後、インデントが異なる関数内のエラーが固定された列ではなく、該当するソース位置を指すことを確認します。

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

評価

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

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

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