MYPYPATH directory used even if no __init__.py
オープン
まだ誰も着手していません。
bug
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Bug Report
According to the docs, when importing foo.bar, mypy will look through each directory in MYPYPATH and find a match. A directory is matched if it contains a __init__.py(i) file. However, I'm seeing behavior where an empty directory in MYPYPATH causes typechecking to fail.
To Reproduce
echo 'from foo.types import Foo' > main.py
mkdir -p foo/types/
echo 'Foo = 123' > foo/types/__init__.py
mkdir -p include/foo/types/
python3.13 -m venv venv
venv/bin/pip install mypy
# passes
rm -rf .mypy_cache && venv/bin/mypy main.py
# fails
rm -rf .mypy_cache && MYPYPATH=include venv/bin/mypy main.py
Expected Behavior
If <dir> does not contain any __init__.py files recursively, then adding MYPYPATH=<dir> should not make any difference
Actual Behavior
$ rm -rf .mypy_cache && venv/bin/mypy main.py
Success: no issues found in 1 source file
$ rm -rf .mypy_cache && MYPYPATH=include venv/bin/mypy main.py
main.py:1: error: Module "foo.types" has no attribute "Foo" [attr-defined]
Found 1 error in 1 file (checked 1 source file)
Your Environment
- Mypy version used:
- Mypy command-line flags:
- Mypy configuration options from
mypy.ini(and other config files): - Python version used:
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
示されている2つの mypy コマンドを使用して、main.py、foo/types/init.py、および空の include/foo/types/ ディレクトリで問題を再現します。MYPYPATH のモジュール解決を追跡し、このレイアウトのリグレッションテストを追加します。空のパスを追加しても、型チェックが成功する結果が変わらなければ完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100