mypy does not show error in excluded folder when PYTHONPATH set

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

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

評価

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

調査の方向性

excluded_folder/excluded.py と included_folder/included.py を含む再現用のパッケージレイアウトから始め、次に PYTHONPATH=. の有無による 2 つの mypy コマンドを比較します。--exclude とインポートされたモジュールがどのように検出されるかを追跡します。PYTHONPATH=. を指定した呼び出しで excluded.py 内の互換性のない戻り値が報告され、両方のコマンドをカバーするリグレッションテストがあれば完了です。

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

説明

bug

Bug Report

As far as I understand, when I use the exclude setting for some folder mypy should still show errors in these packages when imported, because of the follow imports logic. However, if I set the PYTHONPATH to the current working directory, it does not show these errors anymore.

To Reproduce
Here is the folder structure:

src/
|--excluded_folder/
|           |-- excluded.py
|           |-- __init__.py
|--included_folder/
            |-- included.py
            |-- __init__.py

The contents of the file excluded.py are as follows:

def function() -> str:  # obviously wrong return type
        return 5

File included.py looks like so:

from excluded_folder.excluded import function

print(function)

Now, if i run mypy like so, with the setting to exclude the excluded folder, it reports this:

$ mypy --strict --exclude excluded_folder src                          
src/excluded_folder/excluded.py:3: error: Incompatible return value type (got "int", expected "str")  [return-value]
Found 1 error in 1 file (checked 2 source files)

This is what i would expect. It still shows the errors in the file, although excluded.

But if i run mypy with PYTHONPATH set to the current working directory, it does not show any error anymore:

% PYTHONPATH=. mypy --strict --exclude excluded_folder src
Success: no issues found in 2 source files

Expected Behavior
Mypy should also show the errors when the PYTHONPATH is set.

Actual Behavior
Mypy does not show the errors when the PYTHONPATH is set.

Your Environment

  • Mypy version used: mypy 1.8.0 (compiled: yes)
  • Mypy command-line flags: see commands above
  • Mypy configuration options from mypy.ini (and other config files): none
  • Python version used: Python 3.11.3
主要言語
Python
スター
20.6k
フォーク
3.3k
平均マージ
1日 18時間
マージ済み PR(30日)
54

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

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

はじめの一歩

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

python/mypy のほかの issue

python/mypy の issue をすべて見る

似ている issue

Python の issue をもっと見る

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

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