facebook / facebook/pyrefly

Incorrect error from np.ndarray /= float32

Open
#339 2 comments 0 reactions 0 assignees View on GitHub
typechecking
Dominant language
Rust
Stars
7k
Forks
516
PR merge metrics
No merged PRs in 30d

Description

### Describe the Bug

Pyrefly marks line below `a /= 2.0` as _not supported_ , but it is valid code

```
import numpy as np

a: np.ndarray[tuple[float, ...], np.dtype[np.float32]] = np.arange(9, dtype=np.float32)
print(a)
a /= 2.0
print(a)
```

### Sandbox Link

_No response_

### (Only applicable for extension issues) IDE Information

```
[Trace - 5:23:14 PM] Received notification 'textDocument/publishDiagnostics'.
Params: {
"diagnostics": [
{
"code": "no-matching-overload",
"message": "`/=` is not supported between `ndarray[tuple[float, ...], dtype[floating[_32Bit]]]` and `float`\n No matching overload found for function `numpy.ndarray.__itruediv__`, reporting errors for closest overload: `(_NestedSequence[builtins.bool | float | int] | _NestedSequence[_SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[floating[Any]] | dtype[integer[Any]]]] | _SupportsArray[dtype[numpy.bool[builtins.bool]] | dtype[floating[Any]] | dtype[integer[Any]]] | builtins.bool | float | int) -> ndarray[tuple[float, ...], dtype[floating[_32Bit]]]`",
"range": {
"end": {
"character": 8,
"line": 4
},
"start": {
"character": 0,
"line": 4
}
},
"severity": 1,
"source": "Pyrefly"
},
{
"code": "bad-argument-type",
"message": "Argument `ndarray[tuple[float, ...], dtype[floating[_32Bit]]]` is not assignable to parameter with type `ndarray[tuple[int, ...], dtype[float64]]` in function `numpy.ndarray.__itruediv__`",
"range": {
"end": {
"character": 8,
"line": 4
},
"start": {
"character": 0,
"line": 4
}
},
"severity": 1,
"source": "Pyrefly"
}
],
"uri": "file:///mnt/Data/CPP_Projects/test.py"
}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.