python / python/mypy

Allow ignore to be on any line of multi-line statement

オープン
#12,341 コメント 2 件 リアクション 4 件 担当者 0 名 GitHub で見る

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

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

説明

Feature

Currently, comments can be added to a line to ignore either all errors (# type: ignore), or a specific error code (eg. # type: ignore[call-arg]). When a single statement spans multiple lines, the comment has to be added on the line that mypy "decides" is the one with the error (is it the first line of the expression, rather than first line of the statement?). In some cases, it would make sense to allow the comment to be on a different line of the same statement. I propose allowing it to be on any line of the statement, and therefore to apply to the whole statement.

Pitch
Sometimes it makes more sense for it to be another line, such as when importing something that mypy thinks does not exist, it makes sense to have the ignore on the same line as the attribute that is reported as not existing.

from typing import ( # ignore currently needs to be here
    Union,
    DoesNotExist, # type: ignore[error attr-defined]
)

Sometimes, a formatter like black changes a long line into a multiple line statement. The comment that was at the end of the line is moved to the end of the last line.

def foo(bar:int) -> str: ...
def baz() -> int: ...

a = ( # type: ignore[call-arg]
    "something" 
    if baz() > 0 else 
    foo() # ignore currently needs to be here
)  # formatters (eg. black) often put ignore here

https://mypy-play.net/?mypy=latest&python=3.10&flags=show-error-codes%2Cstrict%2Cwarn-unused-ignores&gist=e41c530d401ac4f21cb7a21e68fea141

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

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

はじめの一歩

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

調査の方向性

2つの複数行の例とリンクされた mypy-play の再現から始め、mypy が type: ignore コメントを文に関連付ける方法を追跡してください。完了条件は、1つの複数行文の任意の行にある ignore が、その文に関連するエラーを、特定のコードも含めて抑制し、別々の文の動作は変更しないことです。

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

評価

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

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

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