mypy sometimes emits fewer errors when running on multiple files at once

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

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

評価

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

調査の方向性

repro.zip を展開し、レポートにある 2 つのコマンドを foo.py と bar.py に対して実行して、異なる診断を再現します。ファイルをまとめてチェックする際に mymodule.a と mymodule.b のインポートがどのように処理されるかを追跡し、その後、属性がないことを示すエラーが両方の呼び出しで引き続き報告されることを確認します。

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

説明

bug

Bug Report

Hello there,

I am witnessing (rare) cases where mypy emits fewer errors when running on multiple files at the same time than when running on each file individually.

More specifically, I noticed that mypy can fail to report an error when an import for a submodule is missing a one file but present in another file.

I failed to find anything relevant in the documentation or in the existing issues, so I thought I'd let you know. Below is my attempt at a minimal reproducible example.

To Reproduce

(Since multiple files are needed, here is an archive with the reproduction case: repro.zip)

Given a module mymodule with nested modules a and b, and this file foo.py:

import mymodule.a


def blah() -> None:
    mymodule.b.fn()


blah()

As expected, when called on foo.py, mypy emits an error:

$ mypy --cache-dir /dev/null foo.py
foo.py:5: error: Module has no attribute "b"
Found 1 error in 1 file (checked 1 source file)

yet if I add to mypy's command line a second file which does import mymodule.b, say bar.py:

import mymodule.b

then mypy does not emit the error any more, even though I would expect it to:

$ mypy --cache-dir /dev/null foo.py bar.py
Success: no issues found in 2 source files

Your Environment

I used mypy 0.991 on Ubuntu 22.04 with python 3.10.6; I can reproduce this behavior with master, as well as python 3.8, and older versions of mypy.

主要言語
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 を短くまとめたダイジェスト。