v1.2 tensor-shapes: bitwise `|` is corrupted with `@shaped_array`
- Dominant language
- Rust
- Stars
- 7k
- Forks
- 516
- PR merge metrics
- No merged PRs in 30d
Description
### Describe the Bug
Under pyrefly 1.2, using `@shaped_array` corrupts the return type of the bitwise `|` function, returning `type[Array]` regardless of the annotation of the output. Here's a minimal self-contained example.
This seems to be isolated to `__or__` / `|`; if the example is modified to use `__and__` / `&` or another binary operator, there is no error.
```python
from shape_extensions import shaped_array, IntTuple, IntVar
@shaped_array(shape="Shape")
class Array[Shape: IntTuple]:
shape: Shape
def __or__(self, other: Array[Shape]) -> Array[Shape]:
...
def f[N: IntVar](A: Array[[N]], B: Array[[N]]) -> Array[[N]]:
return A | B
```
```
$ uv run pyrefly --version
pyrefly 1.2.0
$ uv pip list | grep pyrefly-shape-extensions
pyrefly-shape-extensions 1.2.0
$ uv run pyrefly check failure.py
ERROR Returned type `type[Array[[N]]]` is not assignable to declared return type `Array[[N]]` [bad-return]
--> failure.py:11:12
|
10 | def f[N: IntVar](A: Array[[N]], B: Array[[N]]) -> Array[[N]]:
| ---------- declared return type
11 | return A | B
| ^^^^^
|
INFO 1 error
```
I include the sandbox link below, but note that `shape_extensions` is not available there.
### Sandbox Link
https://pyrefly.org/sandbox/?project=v2.pZS9DoMgFIVfheigQyM7SQfdupgm7aaEkEq0ixjApo_fy0UNdnBxUq7cIz_fOYeRaQc5KaG-To1-R5v3sd4JaYyEFL2N7jmDofAN4gytGk_JcXBtk4d_tgncTnBi6b82WGWbDF_OGJsYCT2RvYTQZrOqdoMyLBbiyFxciIgtisJLLT5ravwrLJnn5SrS1JxfSBUPI0U_XMEI9ijBmBXexx8NKbmHAlkOFnIQMOpnSFs4TFhICkGryODcZBmla7s2PVUj7fTL0l0HJR58-ZFvzPC9HNFIrwXZMxhmgcLsCMLMMwgzDrn6AQ
### (Only applicable for extension issues) IDE Information
_No response_
Contributor guide
Research direction
Start with the self-contained example in failure.py and run `uv run pyrefly check failure.py` using pyrefly 1.2.0 and pyrefly-shape-extensions 1.2.0. Trace the handling of `__or__` for the `@shaped_array` type and add a regression test for this case. Done means the expression is accepted with return type `Array[[N]]`, without the reported `type[Array[[N]]]` error.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 55/100