Hacktoberfest 2026:維護者為十月標記出來的 issue,仍然開放、適合新手。 瀏覽 Hacktoberfest issue

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

未關閉
#261 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

@Doribelove 已經在處理了。

開始於 2026年10月21日。

  • #270 來自 @Doribelove —— 未關閉

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
52/100
Issue 類型
缺陷
描述清晰度
基本清楚
活躍度
活躍
技術堆疊
python
領域
robotics

研究方向

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

主要語言
Python
星號
648
分支
108
平均合併
9 天 19 小時
30 天內合併 PR
9

環境準備

這個專案沒有提供開發容器、Dockerfile 或貢獻指南,環境需要你自己搭建:先看它的 README,通用步驟見我們的新手貢獻指南。

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

rai-opensource/spatialmath-python 的其他 Issue

查看 rai-opensource/spatialmath-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。