Importing unstubbed submodules of stubbed modules with silent imports gives inconsistent errors

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

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

評価

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

調査の方向性

Start by reproducing the three commands in the issue with mypy's silent-imports handling, then trace how import x.y differs from from x import y when x has a stub and y does not. Done means the inconsistent behavior is resolved and the incomplete-stub case produces the intended diagnostic consistently.

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

説明

bug needs discussion priority-1-normal topic-usability

In this example, the boto package has a stub, but the boto.foo module does not:

$ python3 -m mypy --py2 --silent-imports -c 'import boto.foo'
# no error
$ python3 -m mypy --py2 --silent-imports -c 'from boto import foo'
<string>:1: error: Module has no attribute 'foo'
$ python3 -m mypy --py2 --silent-imports -c 'import boto.foo; boto.foo'
<string>:1: error: "module" has no attribute "foo"
# in real code, this error is on line where boto.foo is used

As you can see, the behavior here is inconsistent. import boto.foo gives no error, but attempting to use boto.foo later in the program does give an error.

I think the correct behavior here is for import x.y with --silent-imports to be an error when x has a stub but y does not, because this feels conceptually similar to other cases of incomplete stubs. Otherwise, you'd be in danger of importing nonexistent submodules from packages you have full stubs for, with no way to lock that down. The only downside to this approach is it means you have to use a type ignore when the stubs are incomplete, but that's already the case most of the time.

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