`--warn-return-any` not applied to generics
オープン
まだ誰も着手していません。
feature
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Bug Report
When a function annotated to return tuple[T] returns tuple[Any] no error is raised. Same with list.
To Reproduce
from __future__ import annotations
from typing import Any
def passes() -> tuple[str]:
a: Any
return (a,)
def fails_1() -> tuple[str]:
a: int
return (a,)
# error: Incompatible return value type (got "Tuple[int]", expected "Tuple[str]")
def fails_2() -> str:
a: Any
return a
# error: Returning Any from function declared to return "str"
Expected Behavior
I'd expect passes() to fail with error: Returning Tuple[Any] from function declared to return "Tuple[str]" when using mypy with --strict
Actual Behavior
Tuple[Any] is inferred to Tuple[str]
Your Environment
- Mypy version used: 0.812
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files):
# setup.cfg
[mypy]
python_version = 3.8
strict = true
warn_unreachable = true
implicit_reexport = true
ignore_missing_imports = true
- Python version used: 3.9.1
- Operating system and version: macOS 10.13.6
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
tuple[str]、tuple[Any]、list、Any を返す処理を含む、提供された Python の再現コードから始め、報告された strict 設定で実行します。ジェネリックな戻り値の型がどのように推論およびチェックされるかを追跡し、次にタプルの場合のカバレッジを追加して、期待される Returning Tuple[Any] 診断が生成されることを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 48/100