python / python/mypy

inline configurations (mypy comments) in strings still work

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

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

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

説明

Bug Report

I take it the mypy inline configuration comments are supposed to work like regular hot comments, and not just activate whenever they appear as characters in the source file, such as in a string. However, as I discovered while investigating https://github.com/python/mypy/pull/17875#issuecomment-2939335586, they aren't actually parsed according to the Python syntax rules (because this would be slower and more complicated, at least given our current implementation) and therefore they do work if they're in a string, provided they are at the start of a line.

For example, in the following code, untyped defs are disallowed and an error is raised:

"""
This is just a silly little multi-line string literal, surely it couldn't—
# mypy: disallow-untyped-defs
"""
def foo():
    return 1

Your Environment

  • Mypy version used: this was probably 1.15, but I'd be surprised if it's been fixed by 1.17 (current as of time of writing)

Related

This, #12358, and https://github.com/python/mypy/issues/19366 form a loose family of "things we could easily fix if we had a parser that told us about comments to begin with" ie if https://github.com/python/mypy/pull/17875#issuecomment-2587759851 ¶2 or https://github.com/python/cpython/issues/101494#issuecomment-2395119743 were implemented.

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

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

はじめの一歩

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

調査の方向性

issue の reproducer から始め、inline-configuration に関するリンク先のドキュメント、issue #12358、issue #19366、参照されている pull request、および CPython の議論を読みます。文字列内の mypy 設定コメントが無視され、一方で実際のソースコメント内の同じコメントは引き続き機能すれば完了です。

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

評価

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

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

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