mypy resolves symbol incorrectly with builtins import cycle
オープン
まだ誰も着手していません。
bug
topic-import-cycles
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Context: https://github.com/python/typeshed/pull/6289
To reproduce:
- check out typeshed
git checkout 9eabedca5f47a710f29d6e3e2b3a389853fab5aa- apply this patch
diff --git a/stdlib/builtins.pyi b/stdlib/builtins.pyi
index 2393f3c9..0d2ea882 100644
--- a/stdlib/builtins.pyi
+++ b/stdlib/builtins.pyi
@@ -717,6 +717,7 @@ class bool(int):
def __rxor__(self, __x: int) -> int: ...
def __getnewargs__(self) -> tuple[int]: ...
+@final
class slice(object):
start: Any
step: Any
Then run:
mypy --python-version 3.10 --no-incremental --custom-typeshed-dir . stdlib/_ast.pyi stdlib/ast.pyi
and note that mypy incorrectly resolves slice to builtins.slice instead of ast.slice in ast.pyi
Note that if you change the order of files, it works just fine:
mypy --python-version 3.10 --no-incremental --custom-typeshed-dir . stdlib/ast.pyi stdlib/_ast.pyi
It's a pretty weird case, import cycle with builtins, collision with name in builtins, from _ast import * in ast.pyi, etc. But a scary kind of bug :-)
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
9eabedca5f47a710f29d6e3e2b3a389853fab5aa のコミットにある stdlib/builtins.pyi、stdlib/_ast.pyi、stdlib/ast.pyi を使って再現から始めます。2 つのファイル順序で両方の mypy コマンドを実行し、ast.pyi が slice を builtins.slice に解決する理由を追跡します。完了条件は、報告されている順序依存の解決が、ファイル順序に依存せずに修正されていることです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 45/100