[tensor-shapes] Missing scalar divisor overloads for torch.fmod and Tensor.fmod
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 70/100
Línea de trabajo
Reproduce primero con el repro.py dado y el comando de comprobación de pyrefly; el fallo está en pyrefly-torch-stubs, no en pyrefly en sí, así que localiza dónde se declaran torch.fmod y Tensor.fmod y la firma que solo admite un divisor tensor. Añade una sobrecarga escalar para cada uno que devuelva la forma de entrada S, luego vuelve a ejecutar el repro para confirmar que ambas llamadas pasan mientras el comportamiento con divisor tensor sigue igual. Está terminado cuando desaparecen los dos errores reportados y las llamadas existentes con broadcasting siguen pasando la comprobación de tipos.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Describe the Bug
With pyrefly-torch-stubs==1.5.0, passing a Python float divisor to either torch.fmod(x, divisor) or x.fmod(divisor) produces a false positive (bad-argument-type). PyTorch documents a scalar divisor and gives an example with a Python float. Both calls should type-check and preserve the input tensor shape S. PyTorch fmod documentation
Reproduction
Save this as repro.py in an empty directory.
from __future__ import annotations
from typing import TYPE_CHECKING
import torch
if TYPE_CHECKING:
from shape_extensions import IntTuple
from torch import Tensor
def functional[S: IntTuple](x: Tensor[S], divisor: float) -> Tensor[S]:
return torch.fmod(x, divisor)
def method[S: IntTuple](x: Tensor[S], divisor: float) -> Tensor[S]:
return x.fmod(divisor)
An empty Pyrefly configuration is sufficient, then run thuis.
touch pyrefly.toml
uv venv --python 3.13.18 .venv
uv pip install --python .venv/bin/python --index https://download.pytorch.org/whl/cpu 'torch==2.14.0+cpu'
uv pip install --python .venv/bin/python pyrefly==1.5.0 pyrefly-torch-stubs==1.5.0
.venv/bin/pyrefly check --python-interpreter-path .venv/bin/python --output-format min-text repro.py
Pyrefly exits with status 1 and underlines the divisor in both calls.
ERROR repro.py:13:26-33: Argument `float` is not assignable to parameter `other` with type `Tensor[@_]` in function `torch.fmod` [bad-argument-type]
ERROR repro.py:17:19-26: Argument `float` is not assignable to parameter `other` with type `Tensor[@_]` in function `torch.Tensor.fmod` [bad-argument-type]
Both functions run with the same float argument.
.venv/bin/python - <<'PY'
import torch
from repro import functional, method
x = torch.tensor([-0.25, 1.25])
print(functional(x, 0.5).tolist())
print(method(x, 0.5).tolist())
PY
Both print [-0.25, 0.25]. Changing just the two divisor annotations to Tensor[[]] makes the type check pass. The current shape stubs declare a tensor divisor in both places. A scalar overload returning the input shape would cover these calls while preserving the existing broadcasting behavior for tensor divisors.
Sandbox Link
(Only applicable for extension issues) IDE Information
No response
- Lenguaje dominante
- Rust
- Estrellas
- 7.2k
- Forks
- 578
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de facebook/pyrefly
-
good first issue typechecking
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
cargo b warning: unused dependency `zstd`Posiblemente ocupada @Narendersingh007 la tomó hace 4 días. Abiertogood first issue
Dificultad 1/5 Menos de una hora Aptitud para principiantes 88/100
-
Dificultad 4/5 3-5 días Aptitud para principiantes 30/100
-
pydantic
Dificultad 4/5 3-5 días Aptitud para principiantes 35/100
-
False negative when assigning generic function without parameter default to callback protocolAbiertotypechecking
Dificultad 4/5 3-5 días Aptitud para principiantes 40/100
Todos los issues de facebook/pyrefly
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 62/100
eventflux-io/eventflux#203 ·
Los mantenedores suelen responder en 1 día
-
bug ui
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
userFRM/egui-charts#4068 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 82/100
trezor/trezor-firmware#8357 ·
Los mantenedores suelen responder en 2 días
-
fuzz-crash review-followup
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
Los mantenedores suelen responder en 1 día