Skip to content

np.isclose return value incorrectly inferred as bool[bool] #573

@my1e5

Description

@my1e5

Summary

When using np.isclose, ty infers the result as bool[bool], causing it to report that the result is not iterable.

MRE

from typing import reveal_type

import numpy as np
import numpy.typing as npt

x: npt.NDArray[np.bool_] = np.isclose([1e10, 1e-7], [1.00001e10, 1e-8])

reveal_type(x)

for val in x:
    print(val)

ty

$ uvx --with numpy==2.2.6 ty check dev/ty.py 
WARN ty is pre-release software and not ready for production use. Expect to encounter bugs, missing features, and fatal errors.
info[revealed-type]: Revealed type
  --> dev\ty.py:8:13
   |
 6 | x: npt.NDArray[np.bool_] = np.isclose([1e10, 1e-7], [1.00001e10, 1e-8])
 7 |
 8 | reveal_type(x)
   |             ^ `bool[bool]`
 9 |
10 | for val in x:
   |

error[not-iterable]: Object of type `bool[bool]` is not iterable
  --> dev\ty.py:10:12
   |
 8 | reveal_type(x)
 9 |
10 | for val in x:
   |            ^
11 |     print(val)
   |
info: It doesn't have an `__iter__` method or a `__getitem__` method
info: rule `not-iterable` is enabled by default

Found 2 diagnostics

mypy

$ uvx --with numpy==2.2.6 mypy  dev/ty.py 
dev\ty.py:8: note: Revealed type is "numpy.ndarray[builtins.tuple[builtins.int, ...], numpy.dtype[numpy.bool[builtins.bool]]]"
Success: no issues found in 1 source file

Version

ty 0.0.1-alpha.8 (c1337c9 2025-06-02)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions