expand_dims(None) raises TypeError although None is its documented default
维护者通常 1 天内回复
评估
调研方向
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.
由索引模型根据 Issue 内容生成。
描述
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).
- 主要语言
- Python
- 星标
- 648
- 派生
- 108
- 平均合并
- 9 天 19 小时
- 30 天内合并 PR
- 9
环境准备
这个项目没有提供开发容器、Dockerfile 或贡献指南,环境需要你自己搭建:先看它的 README,通用步骤见我们的新手贡献指南。
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
rai-opensource/spatialmath-python 的其他 Issue
-
trlog2 loses the quadrant for valid SO(2) and SE(2) rotations可能已有人在做 @vera-rubin 于 6 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 72/100
rai-opensource/spatialmath-python#252 ·
维护者通常 1 天内回复
-
documentation
难度 2/5 1-3 小时 新手友好度 74/100
rai-opensource/spatialmath-python#235 ·
维护者通常 1 天内回复
-
enhancement
难度 2/5 1-3 小时 新手友好度 65/100
rai-opensource/spatialmath-python#32 · 4 条评论 ·
维护者通常 1 天内回复
-
enhancement
难度 4/5 3-5 天 新手友好度 45/100
rai-opensource/spatialmath-python#268 ·
维护者通常 1 天内回复
-
documentation enhancement
难度 5/5 一周以上 新手友好度 15/100
rai-opensource/spatialmath-python#257 · 1 条评论 ·
维护者通常 1 天内回复
查看 rai-opensource/spatialmath-python 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 74/100
zach-blumenfeld/aip#13 ·
-
难度 2/5 1-3 小时 新手友好度 80/100
nathanmarlor/foxess_modbus#1287 ·
维护者通常 4 天内回复
-
bug good first issue help wanted
难度 2/5 1-3 小时 新手友好度 84/100
OpenLakeForge/openlakeforge#498 ·
维护者通常 1 天内回复
-
good first issue hacktoberfest help wanted python
难度 2/5 1-3 小时 新手友好度 73/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 69/100
pollen-robotics/reachy_mini#1493 ·
维护者通常 1 天内回复