expand_dims(None) raises TypeError although None is its documented default
I maintainer di solito rispondono entro 1 giorno
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 52/100
Direzione di ricerca
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.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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).
- Lingua principale
- Python
- Stelle
- 648
- Fork
- 108
- Merge medio
- 9g 19h
- PR unite (30g)
- 9
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di rai-opensource/spatialmath-python
-
trlog2 loses the quadrant for valid SO(2) and SE(2) rotationsForse già presa @vera-rubin l’ha presa 8 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
rai-opensource/spatialmath-python#252 ·
I maintainer di solito rispondono entro 1 giorno
-
Very long delay (10–20 s) on first plot in a fresh environment: Matplotlib font-cache buildForse già presa Una pull request collegata a questa issue è aperta o già unita. Apertadocumentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
rai-opensource/spatialmath-python#235 ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
rai-opensource/spatialmath-python#32 · 4 commenti ·
I maintainer di solito rispondono entro 1 giorno
-
enhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 45/100
rai-opensource/spatialmath-python#268 ·
I maintainer di solito rispondono entro 1 giorno
-
documentation enhancement
Difficoltà 5/5 Più di una settimana Idoneità per principianti 15/100
rai-opensource/spatialmath-python#257 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di rai-opensource/spatialmath-python
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
CLIMADA-project/climada_python#1337 ·
I maintainer di solito rispondono entro 3 giorni
-
tail without reverseAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
8go/matrix-commander#233 ·
-
documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 66/100
-
documentation enhancement priority:high size:M
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
I maintainer di solito rispondono entro 1 giorno
-
Validate non-divisible effective batch sizes in the Unsloth LoRA backendForse già presa @debesh-biswas l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100