mypy assumes `importlib.metadata` is implicitly imported via `importlib`?
オープン
まだ誰も着手していません。
bug
topic-runtime-semantics
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Bug Report
mypy seems to assume that import importlib brings in the relevant submodules (though I can't see anything in typeshed that would indicate this?) even though it does not
importlib.metadata is not implicitly brought in by importlib:
$ python3 -c 'import importlib; importlib.metadata'
Traceback (most recent call last):
File "<string>", line 1, in <module>
AttributeError: module 'importlib' has no attribute 'metadata'
To Reproduce
import importlib
reveal_type(importlib.metadata) # expected error but none?
import urllib
reveal_type(urllib.parse) # similar situation but properly errors!
Expected Behavior
I expect two errors, but I only get one
Actual Behavior
$ mypy t.py
t.py:3: note: Revealed type is "types.ModuleType"
t.py:7: error: Module has no attribute "parse" [attr-defined]
t.py:7: note: Revealed type is "Any"
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used: 1.13.0
- Mypy command-line flags: n/a
- Mypy configuration options from
mypy.ini(and other config files): n/a - Python version used: 3.13.0
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
t.py の最小再現から始め、Python 3.13 上で mypy 1.13.0 を実行してください。mypy が importlib.metadata を urllib.parse と比較してどのように処理するかを比較し、その後、診断結果の違いの原因となっている import 処理を追跡してください。mypy が importlib.metadata への不足しているアクセスを報告し、既存の urllib.parse のエラーを維持すれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 45/100