Star imports can't be redefined
まだ誰も着手していません。
- 主要言語
- 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.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
a.py と b.py の再現から始め、その後、mypy による star import とそれに続く x のアノテーションの扱いを、Python の実行時の動作と比較します。socket.pyi の例を実際のケースとして使用し、選択的なオーバーライドとその revealed type を対象とする回帰テストを追加します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 42/100