Mypy not reporting "undefined" variable.
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Bug Report
When using a "undefined" variable, which will immediately crash the code when running it, mypy does not report anything about it. Is it normal ?
I feel like mypy should report it but maybe I am wrong because this isn't a typing error. On the other hand, this error is only possible because typing annotations exist . What do you think ?
To Reproduce
Dump this in a file main.py:
number: int
print(number)
Gist URL: https://gist.github.com/mypy-play/31d3775229a6fe01af6bbb09b9230a18
Playground URL: https://mypy-play.net/?mypy=latest&python=3.11&gist=31d3775229a6fe01af6bbb09b9230a18
Expected Behavior
An error message, maybe something like this.
main.py:2: error: Using an undefined variable, a value must be set before first. [var-undefined]
Actual Behavior
$ mypy --strict main.py
Success: no issues found in 1 source file
python main.py
Traceback (most recent call last):
File "/home/user/main.py", line 2, in <module>
print(number)
^^^^^^
NameError: name 'number' is not defined
Your Environment
- Mypy version used: 1.3.0
- Mypy command-line flags: --strict
- Mypy configuration options from
mypy.ini(and other config files): nothing - Python version used: 3.11.3
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、main.py の例と mypy --strict main.py を使って動作を再現します。このケースに [var-undefined] のような診断を付けるべきかを判断する前に、checker がアノテーションのみの変数をどのように処理するかを確認します。適切なテストと診断によって動作がカバーされているか、期待される動作が未サポートとして文書化されていれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 42/100