Overload resolution collapses to Any when Any is nested inside a generic argument, not just top-level
まだ誰も着手していません。
評価
調査の方向性
まず、提供されたスニペットを mypy 2.3.0 で実行し、ドキュメントの「Type checking calls to overloads」セクションを読んでください。Sequence[Any] と Sequence[int] のオーバーロード解決を追跡します。意図した動作が確立され、表示された型、実装、またはドキュメントがその判断と一致すれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Bug Report
The docs state the return type becomes Any only when "an argument [is] of type Any". But when the Any is nested inside a generic type argument (Sequence[Any] vs Sequence[int]), mypy also collapses the result to Any, even though the first overload matches unambiguously. Is this intended? If so, the "Type checking calls to overloads" section should probably document the nested case.
To Reproduce
from collections.abc import Sequence
from typing import Any, overload, reveal_type
@overload
def f(s: Sequence[int]) -> str: ...
@overload
def f(s: object) -> int: ...
def f(s: object) -> int | str:
return "2"
concrete: Sequence[int] = [1]
nested_any: Sequence[Any] = [1]
reveal_type(f(concrete)) # Revealed type is "str" (expected)
reveal_type(f(nested_any)) # Revealed type is "Any" (surprising)
Expected Behavior
reveal_type on Sequence[Any] should show "str"
Actual Behavior
reveal_type on Sequence[Any] shows "Any"
Your Environment
- Mypy version used: mypy 2.3.0
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: Python 3.14.6
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- 平均マージ
- 1日 12時間
- マージ済み PR(30日)
- 58
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python/mypy のほかの issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
-
bug topic-configuration topic-error-reporting
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
bug topic-attrs
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
anthropics/skills#1811 · コメント 1 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
speaches-ai/speaches#678 ·
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
datalayer/mcp-compose#42 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
conda-forge/spacy-feedstock#177 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
UKGovernmentBEIS/inspect_evals#2523 ·