Any is inferred with a certain combination of overloads and generics
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Bug Report
(I couldn't come up with a better title, please fix)
I've got a piece of code where the inferred type is sometimes Any when it shouldn't be, and the difference between getting Any and the correct result doesn't make sense so it looks like a mypy bug to me. I may be wrong though.
The background: I'm trying to refactor and fix the overloads for https://github.com/scrapy/scrapy/blob/2b9e32f1ca491340148e6a1918d1df70443823e6/scrapy/utils/defer.py#L360, I've simplified the overloads and ignored the "overlapping signatures" error per https://stackoverflow.com/questions/60222982/type-annotation-for-overloads-that-exclude-types-something-vs-everything-else but the inferred result of the function works fine only if the input coroutine doesn't return e.g. List[Any]. It doesn't seem to fall back to the second overload either, as that wouldn't result in Any too. Overall it doesn't look like something with my code but maybe I'm missing something.
To Reproduce
https://gist.github.com/mypy-play/29b3eb14ab12db21dc8f52594f40c392
Expected Behavior
I expect the revealed type to always be a Deferred with the same param as the coroutine result type and never Any.
Actual Behavior
It's Any when, it looks like, the argument type has Any in it.
Your Environment
- Mypy version used: 1.10.0
- Python version used: 3.12
- Playground URL: https://mypy-play.net/?mypy=latest&python=3.12&gist=29b3eb14ab12db21dc8f52594f40c392
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンクされている mypy-play の再現例と gist から始め、コルーチンの結果が Any を含む場合と正確な型を含む場合で、オーバーロード解決と明らかになった型を比較します。mypy 1.10.0 および Python 3.12 での動作を確認します。完了の条件は、明らかになった結果が Any になるのではなく、コルーチンの結果の型を一貫して保持することです。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers, devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100