expand_dims(None) raises TypeError although None is its documented default
Les mainteneurs répondent en général sous 1 jour
Évaluation
- Difficulté
- 2/5
- Temps estimé
- 1-3 heures
- Accessibilité débutants
- 52/100
Piste de recherche
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.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Description
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).
- Langage dominant
- Python
- Étoiles
- 648
- Forks
- 108
- Merge moyen
- 9 j 19 h
- PR mergées (30 j)
- 9
Préparer son environnement
Ce projet ne fournit ni conteneur de développement, ni Dockerfile, ni guide de contribution : l'installation est à votre charge. Commencez par son README, et consultez notre guide de la première contribution pour les étapes générales.
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Autres issues de rai-opensource/spatialmath-python
-
trlog2 loses the quadrant for valid SO(2) and SE(2) rotationsPeut-être pris @vera-rubin l’a pris il y a 7 jours. Ouverte
Difficulté 2/5 1-3 heures Accessibilité débutants 72/100
rai-opensource/spatialmath-python#252 ·
Les mainteneurs répondent en général sous 1 jour
-
documentation
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
rai-opensource/spatialmath-python#235 ·
Les mainteneurs répondent en général sous 1 jour
-
enhancement
Difficulté 2/5 1-3 heures Accessibilité débutants 65/100
rai-opensource/spatialmath-python#32 · 4 commentaires ·
Les mainteneurs répondent en général sous 1 jour
-
enhancement
Difficulté 4/5 3-5 jours Accessibilité débutants 45/100
rai-opensource/spatialmath-python#268 ·
Les mainteneurs répondent en général sous 1 jour
-
documentation enhancement
Difficulté 5/5 Plus d'une semaine Accessibilité débutants 15/100
rai-opensource/spatialmath-python#257 · 1 commentaire ·
Les mainteneurs répondent en général sous 1 jour
Toutes les issues de rai-opensource/spatialmath-python
Issues similaires
-
Difficulté 2/5 1-3 heures Accessibilité débutants 82/100
volcengine/OpenViking#6445 ·
Les mainteneurs répondent en général sous 1 jour
-
BUG:Edit Album strips spaces from the password so albums with a leading/trailing space in the password can't be editedPeut-être pris @ManyaJain111 l’a pris aujourd’hui. Ouvertebug enhancement possible-duplicate
Difficulté 2/5 1-3 heures Accessibilité débutants 77/100
AOSSIE-Org/PictoPy#1637 · 4 commentaires ·
Les mainteneurs répondent en général sous 2 jours
-
Difficulté 2/5 1-3 heures Accessibilité débutants 74/100
deepspeedai/DeepSpeed#8884 ·
Les mainteneurs répondent en général sous 3 jours
-
Flaky: test_advisor_live_calibrates_an_unmeasured_circuit ranks engines by a 1.8ms sleep marginOuverte
Difficulté 2/5 1-3 heures Accessibilité débutants 76/100
flagos-ai/FlagQuantum#718 ·
Les mainteneurs répondent en général sous 1 jour
-
bug CI-failure high priority
Difficulté 1/5 Moins d'une heure Accessibilité débutants 86/100
vllm-project/afd-plugin#483 ·
Les mainteneurs répondent en général sous 1 jour