expand_dims(None) raises TypeError although None is its documented default
Los mantenedores suelen responder en 1 día
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 52/100
Línea de trabajo
Start with the expand_dims function in the spatialmath.base module, reading its signature, docstring and the code path that raises TypeError: invalid input type. Reproduce with expand_dims() and expand_dims(None). The issue leaves open whether to return None or remove the default, so confirm the maintainers' choice before editing. Done when the chosen behaviour holds and the existing suite still passes.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
spatialmath.base.expand_dims declares dim with a default of None and documents it (":param dim: dimensions, defaults to None"), but calling it with that value raises:
>>> from spatialmath.base import expand_dims
>>> expand_dims()
TypeError: invalid input type
>>> expand_dims(None)
TypeError: invalid input type
Found while consolidating how RTB resolves a plot or world extent from several candidate sources, where "not given" is a normal state (RTB cannot rely on the default, so it special-cases None before every call).
Current callers already guard it
Every caller in SMTB tests for None before calling, which is the check the function could do itself:
# graphics.py, plotvol2
if dim is None:
ax.autoscale(True)
else:
dims = expand_dims(dim, 2)
The same is true of plotvol3, Animate and the dims argument handling in transforms2d.py.
Suggestion
Return None for None:
def expand_dims(dim: ArrayLike | None = None, nd: int = 2) -> NDArray | None:
if dim is None:
return None
...
Noneis passed through as "unspecified", and the caller decides what that means (autoscale, no limits, use the next candidate).- A default box such as
[-1, 1, -1, 1]would be worse: it invents a value the caller did not give, and would make "not given" indistinguishable from "given as 1". - A wrong-length vector still raises
ValueError, so malformed input still fails loudly. - The return type becomes
NDArray | None, so strictly typed callers need aNonecheck. The existing call sites already have one.
Alternatively, if raising is intended, the signature and docstring should drop the default so that the argument is required.
Tested
With this change SMTB's own suite is unchanged (342 passed before and after). All four SMTB call sites already guard None. One downstream use, in bdsim's GraphicsBlock handling of scale=, would see an invalid scale=None fail later rather than at construction.
Related: #255 (the getvector/getmatrix converters, same family of "accept the natural input" questions).
- Lenguaje dominante
- Python
- Estrellas
- 648
- Forks
- 108
- Merge medio
- 9 d 19 h
- PR fusionados (30 d)
- 9
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
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 rai-opensource/spatialmath-python
-
trlog2 loses the quadrant for valid SO(2) and SE(2) rotationsPosiblemente ocupada @vera-rubin la tomó hace 7 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
rai-opensource/spatialmath-python#252 ·
Los mantenedores suelen responder en 1 día
-
documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
rai-opensource/spatialmath-python#235 ·
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 65/100
rai-opensource/spatialmath-python#32 · 4 comentarios ·
Los mantenedores suelen responder en 1 día
-
enhancement
Dificultad 4/5 3-5 días Aptitud para principiantes 45/100
rai-opensource/spatialmath-python#268 ·
Los mantenedores suelen responder en 1 día
-
documentation enhancement
Dificultad 5/5 Más de una semana Aptitud para principiantes 15/100
rai-opensource/spatialmath-python#257 · 1 comentario ·
Los mantenedores suelen responder en 1 día
Todos los issues de rai-opensource/spatialmath-python
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
volcengine/OpenViking#6445 ·
Los mantenedores suelen responder en 1 día
-
BUG:Edit Album strips spaces from the password so albums with a leading/trailing space in the password can't be editedPosiblemente ocupada @ManyaJain111 la tomó hoy. Abiertobug enhancement possible-duplicate
Dificultad 2/5 1-3 horas Aptitud para principiantes 77/100
AOSSIE-Org/PictoPy#1637 · 4 comentarios ·
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
deepspeedai/DeepSpeed#8884 ·
Los mantenedores suelen responder en 3 días
-
Flaky: test_advisor_live_calibrates_an_unmeasured_circuit ranks engines by a 1.8ms sleep marginAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
flagos-ai/FlagQuantum#718 ·
Los mantenedores suelen responder en 1 día
-
bug CI-failure high priority
Dificultad 1/5 Menos de una hora Aptitud para principiantes 86/100
vllm-project/afd-plugin#483 ·
Los mantenedores suelen responder en 1 día