mypy incorrectly reports incompatible return types for overloaded methods
オープン
まだ誰も着手していません。
bug
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Bug Report
@overload
def foo(cls: type[dict], mapping: SupportsKeysAndGetItem[K, V], /) -> dict[K, V]: ...
@overload
def foo(cls: type[dict], mapping: SupportsKeysAndGetItem[str, V], /, **kwargs: V) -> dict[str, V]: ...
Return types are compatible.
class FrozendictBase(Generic[K, V]):
@overload
def __new__(
cls,
mapping: SupportsKeysAndGetItem[K, V],
/,
) -> 'FrozendictBase[K, V]': ...
@overload
def __new__(
cls,
mapping: SupportsKeysAndGetItem[str, V],
/,
**kwargs: V,
) -> 'FrozendictBase[str, V]': ...
Return types are also compatible, but mypy reports an error.
To Reproduce
- Download file.txt and save as
sandbox.py. - Run
mypy sandbox.py.
Expected Behavior
sandbox.py:8: error: Invariant type variable "V" used in protocol where covariant one is expected
This is due to #5775.
Actual Behavior
sandbox.py:8: error: Invariant type variable "V" used in protocol where covariant one is expected
sandbox.py:39: error: Overloaded function signatures 3 and 4 overlap with incompatible return types
sandbox.py:54: error: Overloaded function signatures 5 and 6 overlap with incompatible return types
Your Environment
- Mypy version used: mypy 0.950
- Mypy command-line flags:
- Mypy configuration options from
mypy.ini(and other config files): - Python version used: Python 3.10.4
- Operating system and version: Windows 10
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
リンク先のファイルをダウンロードして sandbox.py として保存し、その後 mypy sandbox.py を実行してオーバーロードの診断を再現します。オーバーロードされたシグネチャ 3/4 および 5/6 に対する互換性のない戻り値型の報告を調査します。期待される不変な型変数のエラーが残ったまま、それらの報告が表示されなくなれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- compilers, devtools
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100