Partial type that is "initialised" via assignment is only temporarily narrowed by `isinstance`
オープン
まだ誰も着手していません。
bug
topic-type-narrowing
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
In the following example, the last revealed type could/should be Union[builtins.int, None]:
def f() -> bool:
return True
u: int | tuple[int]
x = None
if f():
x = u
if isinstance(x, tuple):
x = x[0]
reveal_type(x) # note: "builtins.int"
reveal_type(x) # note: Revealed type is "Union[builtins.int, Tuple[builtins.int], None]"
See this comment for background information.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず issue の Python 例を再現し、2 つの reveal_type の結果を期待される絞り込みと比較します。背景を把握するために PR #18180 にリンクされたコメントを読み、その後、代入に基づく絞り込みを担う型チェックの経路を追います。最終的に表示される型が int | None になり、示されている動作を退行させなければ完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100