From c46709a84a0e25103ef01a3543ab386f58f36022 Mon Sep 17 00:00:00 2001 From: Mangesh Raut Date: Mon, 26 Oct 2026 02:50:58 +0530 Subject: [PATCH] fix(stubs): support float64 subtraction with float The shaped NumPy stubs lost the concrete float64 promotion for a Python float. Add a specific overload ahead of the generic numeric fallback so the operation is accepted and preserves its dtype. --- .../pyrefly-numpy-stubs/numpy-stubs/__init__.pyi | 8 +++++++- .../pyrefly-numpy-stubs/test/test_dtype_properties.py | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/tensor-shapes/pyrefly-numpy-stubs/numpy-stubs/__init__.pyi b/tensor-shapes/pyrefly-numpy-stubs/numpy-stubs/__init__.pyi index 7cf497070f..bb897617cb 100644 --- a/tensor-shapes/pyrefly-numpy-stubs/numpy-stubs/__init__.pyi +++ b/tensor-shapes/pyrefly-numpy-stubs/numpy-stubs/__init__.pyi @@ -510,7 +510,13 @@ class bool_(generic): class float16(floating): ... class float32(floating): ... -class float64(floating): ... + +class float64(floating): + @overload + def __sub__(self, other: float, /) -> float64: ... + @overload + def __sub__(self, other: _NumberScalar, /) -> number: ... + class longdouble(floating): ... class complex64(complexfloating): ... class complex128(complexfloating): ... diff --git a/tensor-shapes/pyrefly-numpy-stubs/test/test_dtype_properties.py b/tensor-shapes/pyrefly-numpy-stubs/test/test_dtype_properties.py index 8a6ad3710e..24f37ec146 100644 --- a/tensor-shapes/pyrefly-numpy-stubs/test/test_dtype_properties.py +++ b/tensor-shapes/pyrefly-numpy-stubs/test/test_dtype_properties.py @@ -74,6 +74,7 @@ def test_numeric_scalar_operations() -> None: assert_type(float(real), float) assert_type(complex(complex_), complex) assert_shape((real**2).shape, ()) + assert_type(real - 1.0, np.float64) assert_shape((real * 1j).shape, ()) assert_type(1j * real, np.number | complex) assert_shape((complex_ / integer).shape, ())