overloads not properly evaluated with mypy 2.3.0 and numpy 2.5.1
オープン
まだ誰も着手していません。
bug
topic-overloads
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Bug Report
The final reveal_type() below should show DatetimeArray, but it is showing Any
With pyright, ty and pyrefly, it produces the correct result. May be related to #21608
To Reproduce
import numpy as np
from typing import Any, Sequence, overload, reveal_type
class DatetimeArray:
pass
class NumpyExtensionArray:
pass
@overload
def array( # pyright: ignore[reportOverlappingOverload]
data: Sequence[np.datetime64],
) -> DatetimeArray: ...
@overload
def array(data: Sequence[Any]) -> NumpyExtensionArray: ...
def array(data: Sequence[Any]) -> DatetimeArray | NumpyExtensionArray:
return (
DatetimeArray() if isinstance(data[0], np.datetime64) else NumpyExtensionArray()
)
foo1 = [np.datetime64("2026-01-05 23:27:59")]
foo0 = np.datetime64("2026-01-05 23:27:59")
reveal_type(foo0)
reveal_type(foo1)
reveal_type(array(foo1)) # Should be DatetimeArray
Expected Behavior
numpy_datetimearray.py:28: note: Revealed type is "numpy.datetime64[Any]"
numpy_datetimearray.py:29: note: Revealed type is "list[numpy.datetime64[Any]]"
numpy_datetimearray.py:30: note: Revealed type is "DatetimeArray"
Actual Behavior
numpy_datetimearray.py:28: note: Revealed type is "numpy.datetime64[Any]"
numpy_datetimearray.py:29: note: Revealed type is "list[numpy.datetime64[Any]]"
numpy_datetimearray.py:30: note: Revealed type is "Any"
Your Environment
- Mypy version used: 2.3.0
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.12
- Numpy version used: 2.5.1
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
この issue には、リポジトリ内のファイルも既存のテストも記載されていません。まず提供された再現コードを保存し、mypy 2.3.0 で実行してから、2 つの配列シグネチャに対する overload の評価を追跡し、結果を期待される reveal_type の出力と比較してください。呼び出しで DatetimeArray が表示され、このケースをカバーする回帰テストがあれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- numpy, python
- 領域
- devtools, tooling
- issue の種類
- バグ
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 52/100