expand_dims(None) raises TypeError although None is its documented default
Mantenedores costumam responder em até 1 dia
Avaliação
- Dificuldade
- 2/5
- Tempo estimado
- 1-3 horas
- Facilidade para iniciantes
- 52/100
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
...
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).
- 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
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de rai-opensource/spatialmath-python
-
trlog2 loses the quadrant for valid SO(2) and SE(2) rotationsTalvez já em andamento @vera-rubin assumiu há 7 dias. Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 72/100
rai-opensource/spatialmath-python#252 ·
Mantenedores costumam responder em até 1 dia
-
documentation
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
rai-opensource/spatialmath-python#235 ·
Mantenedores costumam responder em até 1 dia
-
enhancement
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 65/100
rai-opensource/spatialmath-python#32 · 4 comentários ·
Mantenedores costumam responder em até 1 dia
-
enhancement
Dificuldade 4/5 3-5 dias Facilidade para iniciantes 45/100
rai-opensource/spatialmath-python#268 ·
Mantenedores costumam responder em até 1 dia
-
documentation enhancement
Dificuldade 5/5 Mais de uma semana Facilidade para iniciantes 15/100
rai-opensource/spatialmath-python#257 · 1 comentário ·
Mantenedores costumam responder em até 1 dia
Todas as issues de rai-opensource/spatialmath-python
Issues semelhantes
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
volcengine/OpenViking#6445 ·
Mantenedores costumam responder em até 1 dia
-
BUG:Edit Album strips spaces from the password so albums with a leading/trailing space in the password can't be editedTalvez já em andamento @ManyaJain111 assumiu hoje. Abertabug enhancement possible-duplicate
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 77/100
AOSSIE-Org/PictoPy#1637 · 4 comentários ·
Mantenedores costumam responder em até 2 dias
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
deepspeedai/DeepSpeed#8884 ·
Mantenedores costumam responder em até 3 dias
-
Flaky: test_advisor_live_calibrates_an_unmeasured_circuit ranks engines by a 1.8ms sleep marginAberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100
flagos-ai/FlagQuantum#718 ·
Mantenedores costumam responder em até 1 dia
-
bug CI-failure high priority
Dificuldade 1/5 Menos de uma hora Facilidade para iniciantes 86/100
vllm-project/afd-plugin#483 ·
Mantenedores costumam responder em até 1 dia