Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

expand_dims(None) raises TypeError although None is its documented default

Ouverte
#261 0 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

@Doribelove y travaille déjà.

Depuis le 21/10/2026.

  • #270 par @Doribelove — ouverte

Évaluation

Difficulté
2/5
Temps estimé
1-3 heures
Accessibilité débutants
52/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
Active
Stack technique
python
Domaine
robotics

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
    ...
  • None is 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 a None check. 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

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de rai-opensource/spatialmath-python

Toutes les issues de rai-opensource/spatialmath-python

Issues similaires

Plus d'issues Python

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.