[stubtest] False positive involving overloaded function with default argument for parameter with type variable
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 45/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 静か
- 技術スタック
- python
- 領域
- devtools, testing-qa
調査の方向性
まず、示されている foo の runtime と stub の組み合わせを stubtest で再現し、次に overload とデフォルト引数の整合性チェックを追跡します。3 番目の overload のケースで誤検知が報告されなくなり、実際に互換性のない runtime のデフォルト値は引き続き検出されれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Bug Report
Given the runtime function:
def foo(x=0, ret=1):
return ret
stubtest is happy with these stubs:
from typing import TypeVar, overload
_T = TypeVar("_T")
@overload
def foo(x: int = 0) -> int: ...
@overload
def foo(x: int, ret: _T) -> _T: ...
but complains about these stubs (with a third overload added):
from typing import TypeVar, overload
_T = TypeVar("_T")
@overload
def foo(x: int = 0) -> int: ...
@overload
def foo(x: int, ret: _T) -> _T: ...
@overload
def foo(x: int = 0, *, ret: _T) -> _T: ... # added
with the error:
error: main.foo is inconsistent, runtime parameter "ret" has a default value of type Literal[1], which is incompatible with stub parameter type _T | _T. This is often caused by overloads failing to account for explicitly passing in the default value.
Stub: in file main.pyi:5
Overload(def (x: int =) -> int, def [_T] (x: int, ret: _T) -> _T, def [_T] (x: int =, *, ret: _T) -> _T)
Inferred signature: def (x: int = ..., ret: _T | _T = ...)
Runtime: in file main.py:1
def (x=0, ret=1)
Found 1 error (checked 1 module)
Your Environment
- Mypy version used: master,
mypy 2.2.0+dev.e15a6d58d - Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: 3.13.13
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- 平均マージ
- 1日 18時間
- マージ済み PR(30日)
- 54
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
python/mypy のほかの issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
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
似ている issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 86/100
zostera/django-bootstrap4#894 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
use-agent-os/agent-os#3276 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
zephyrproject-rtos/zephyr#119726 ·
-
area/auth bug comp/agent P3 platform/discord type/security
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
NousResearch/hermes-agent#117848 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
zilliztech/memsearch#759 ·