From b714a06b66e16a5f9c3e41de3d742fbac472b9a4 Mon Sep 17 00:00:00 2001 From: Mangesh Raut Date: Mon, 26 Oct 2026 02:50:18 +0530 Subject: [PATCH 1/5] Support builtin float with NumPy float64 --- .../pyrefly-numpy-stubs/numpy-stubs/__init__.pyi | 2 +- .../test/test_dtype_properties.py | 12 ++++++++++++ 2 files changed, 13 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..e780160ef0 100644 --- a/tensor-shapes/pyrefly-numpy-stubs/numpy-stubs/__init__.pyi +++ b/tensor-shapes/pyrefly-numpy-stubs/numpy-stubs/__init__.pyi @@ -510,7 +510,7 @@ class bool_(generic): class float16(floating): ... class float32(floating): ... -class float64(floating): ... +class float64(floating, float): ... 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..f08d7241b4 100644 --- a/tensor-shapes/pyrefly-numpy-stubs/test/test_dtype_properties.py +++ b/tensor-shapes/pyrefly-numpy-stubs/test/test_dtype_properties.py @@ -107,6 +107,18 @@ def test_numeric_scalar_operations() -> None: np.float64(1j) # E: not assignable +def test_float64_operations_with_builtin_float() -> None: + real = np.float64(2.0) + builtin_float = 1.0 + scalar_as_float: float = real + + assert_type(scalar_as_float, float) + assert real - builtin_float == 1.0 + assert builtin_float - real == -1.0 + assert real > builtin_float + assert not builtin_float > real + + def test_integer_scalar_array_index() -> None: index = np.ones((), dtype=np.int64) assert_shape(index.shape, ()) From 645740655698d8cd1da2ed7f01c2b926a2335b13 Mon Sep 17 00:00:00 2001 From: Mangesh Raut Date: Mon, 26 Oct 2026 03:46:13 +0530 Subject: [PATCH 2/5] =?UTF-8?q?fix(stubs):=20narrow=20float64=E2=86=94floa?= =?UTF-8?q?t=20ops=20without=20inheriting=20float?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Inheriting builtins.float made ``1j * float64`` resolve via complex*float and broke dtype-properties assert_type (expected 5 errors, got 6). Add float-specific overloads for __sub__/__rsub__ and comparisons only, matching issue #5353 without rewriting reflected numeric ops. --- .../numpy-stubs/__init__.pyi | 29 ++++++++++++++++++- .../test/test_dtype_properties.py | 7 +++-- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/tensor-shapes/pyrefly-numpy-stubs/numpy-stubs/__init__.pyi b/tensor-shapes/pyrefly-numpy-stubs/numpy-stubs/__init__.pyi index e780160ef0..799941571a 100644 --- a/tensor-shapes/pyrefly-numpy-stubs/numpy-stubs/__init__.pyi +++ b/tensor-shapes/pyrefly-numpy-stubs/numpy-stubs/__init__.pyi @@ -510,7 +510,34 @@ class bool_(generic): class float16(floating): ... class float32(floating): ... -class float64(floating, float): ... +class float64(floating): + # Narrow builtin-float support without inheriting float (which + # rewrites reflected ops like ``1j * float64`` via complex*float). + @overload + def __sub__(self, other: float, /) -> float64: ... + @overload + def __sub__(self, other: _NumberScalar, /) -> number: ... + @overload + def __rsub__(self, other: float, /) -> float64: ... + @overload + def __rsub__(self, other: _NumberScalar, /) -> number | complex: ... + @overload + def __gt__(self, other: float, /) -> bool_: ... + @overload + def __gt__(self, other: _NumberScalar, /) -> bool_: ... + @overload + def __ge__(self, other: float, /) -> bool_: ... + @overload + def __ge__(self, other: _NumberScalar, /) -> bool_: ... + @overload + def __lt__(self, other: float, /) -> bool_: ... + @overload + def __lt__(self, other: _NumberScalar, /) -> bool_: ... + @overload + def __le__(self, other: float, /) -> bool_: ... + @overload + def __le__(self, other: _NumberScalar, /) -> bool_: ... + 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 f08d7241b4..67cb58febd 100644 --- a/tensor-shapes/pyrefly-numpy-stubs/test/test_dtype_properties.py +++ b/tensor-shapes/pyrefly-numpy-stubs/test/test_dtype_properties.py @@ -110,9 +110,12 @@ def test_numeric_scalar_operations() -> None: def test_float64_operations_with_builtin_float() -> None: real = np.float64(2.0) builtin_float = 1.0 - scalar_as_float: float = real - assert_type(scalar_as_float, float) + # Ops only — do not inherit builtins.float (breaks 1j * float64 typing). + assert_type(real - builtin_float, np.float64) + assert_type(builtin_float - real, np.float64) + assert_type(real > builtin_float, np.bool_) + assert_type(builtin_float > real, np.bool_) assert real - builtin_float == 1.0 assert builtin_float - real == -1.0 assert real > builtin_float From f98b7061196e30673eb65a430f7aed1f74adf34e Mon Sep 17 00:00:00 2001 From: Mangesh Raut Date: Mon, 26 Oct 2026 03:53:10 +0530 Subject: [PATCH 3/5] style: ruff-format blank line before float64 overloads --- tensor-shapes/pyrefly-numpy-stubs/numpy-stubs/__init__.pyi | 1 + 1 file changed, 1 insertion(+) diff --git a/tensor-shapes/pyrefly-numpy-stubs/numpy-stubs/__init__.pyi b/tensor-shapes/pyrefly-numpy-stubs/numpy-stubs/__init__.pyi index 799941571a..38a202930b 100644 --- a/tensor-shapes/pyrefly-numpy-stubs/numpy-stubs/__init__.pyi +++ b/tensor-shapes/pyrefly-numpy-stubs/numpy-stubs/__init__.pyi @@ -510,6 +510,7 @@ class bool_(generic): class float16(floating): ... class float32(floating): ... + class float64(floating): # Narrow builtin-float support without inheriting float (which # rewrites reflected ops like ``1j * float64`` via complex*float). From 935efbc888179950a5ab2decc90a4beb6921af4e Mon Sep 17 00:00:00 2001 From: Mangesh Raut Date: Mon, 26 Oct 2026 04:11:31 +0530 Subject: [PATCH 4/5] =?UTF-8?q?test:=20add=20assert=5Fshape=20so=20float64?= =?UTF-8?q?=E2=86=94float=20coverage=20runs=20at=20runtime?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Runtime harness rejects tests that only use plain assert/assert_type. --- tensor-shapes/pyrefly-numpy-stubs/test/test_dtype_properties.py | 2 ++ 1 file changed, 2 insertions(+) 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 67cb58febd..1a80cb1b4e 100644 --- a/tensor-shapes/pyrefly-numpy-stubs/test/test_dtype_properties.py +++ b/tensor-shapes/pyrefly-numpy-stubs/test/test_dtype_properties.py @@ -116,6 +116,8 @@ def test_float64_operations_with_builtin_float() -> None: assert_type(builtin_float - real, np.float64) assert_type(real > builtin_float, np.bool_) assert_type(builtin_float > real, np.bool_) + assert_shape((real - builtin_float).shape, ()) + assert_shape((builtin_float - real).shape, ()) assert real - builtin_float == 1.0 assert builtin_float - real == -1.0 assert real > builtin_float From e623d0ea89fb8d3b01508bac5445d8c87c6e481b Mon Sep 17 00:00:00 2001 From: Mangesh Raut Date: Mon, 26 Oct 2026 04:42:05 +0530 Subject: [PATCH 5/5] ci: retrigger macOS/Windows after glean flake Same flake as elsewhere: commands::check::tests::check_writes_cinderx_and_glean_reports_together (assertion failed: facts.contains("public.api.Widget")). Ubuntu + tensor-shape remain green.