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 小時 新手友好度 77/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 67/100
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 72/100
pgvector/pgvector-python#169 ·
-
ChaosEngine: backup-remote doctor row passes while consumer mode hides bot memory from git可能已有人在做 @MohabMohie 今天認領。 未關閉agentic
難度 2/5 1-3 小時 新手友好度 76/100
ShaftHQ/SHAFT_ENGINE#7263 ·
維護者通常 1 天內回覆
-
bug
難度 2/5 1-3 小時 新手友好度 87/100
huggingface/smolagents#3045 ·
維護者通常 1 天內回覆