Hacktoberfest 2026: as issues que os mantenedores marcaram para outubro, abertas e boas para iniciantes. Ver issues do Hacktoberfest

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

Aberta
#261 0 comentários 0 reações 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

@Doribelove já está trabalhando nisso.

Desde 21/10/2026.

  • #270 de @Doribelove — aberto

Avaliação

Dificuldade
2/5
Tempo estimado
1-3 horas
Facilidade para iniciantes
52/100
Tipo de issue
Bug
Clareza
Razoavelmente clara
Status de atividade
Ativa
Stack de tecnologia
python
Domínio
robotics

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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).

Linguagem predominante
Python
Estrelas
648
Forks
108
Merge médio
9d 19h
PRs com merge (30d)
9

Preparar o ambiente

Este projeto não oferece contêiner de desenvolvimento, Dockerfile nem guia de contribuição, então a configuração fica por sua conta: comece pelo README e veja nosso guia da primeira contribuição para os passos gerais.

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de rai-opensource/spatialmath-python

Todas as issues de rai-opensource/spatialmath-python

Issues semelhantes

Mais issues de Python

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.