python / python/mypy

Star imports can't be redefined

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

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

bug
主要言語
Python
スター
20.6k
フォーク
3.3k
PR マージ指標
PR 指標を取得中

説明

Bug Report

Using mypy 0.820+dev.61c346230cf4960c9766f7c2b5bd3312b47f74da and Python 3.9.4:

# a.py

x: int
# and many more definitions
# b.py

from a import *

x: str  # Name "x" already defined (possibly by an import)
reveal_type(x)  # Revealed type is "builtins.int"

This caused us a lot of trouble in python/typeshed#5545 and leads to this horrible and hard to maintain import mess: https://github.com/python/typeshed/blob/6ee67483a30e178f243d3a9a5b5a9bb4b902901a/stdlib/socket.pyi

I understand the warning and I think it makes sense to have to suppress it with # type: ignore. But the the fact that the override behaves differently from runtime is quite problematic as evidenced by socket.py. This is an example from the standard library that relies on the fact that star imports can be overridden selectively.

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

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

はじめの一歩

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

調査の方向性

a.py と b.py の再現から始め、その後、mypy による star import とそれに続く x のアノテーションの扱いを、Python の実行時の動作と比較します。socket.pyi の例を実際のケースとして使用し、選択的なオーバーライドとその revealed type を対象とする回帰テストを追加します。

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

評価

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

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

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