Skip to content

fix: alias importlib.metadata.version to avoid wildcard-import shadowing - #43

Open
petercorke wants to merge 1 commit into
mainfrom
fix/rvctool-version-shadowing
Open

fix: alias importlib.metadata.version to avoid wildcard-import shadowing#43
petercorke wants to merge 1 commit into
mainfrom
fix/rvctool-version-shadowing

Conversation

@petercorke

Copy link
Copy Markdown
Owner

Summary

Fixes #26. rvctool.py imports version from importlib.metadata, then later does from spatialmath.base import *. If spatialmath.base ever exports its own version symbol, the wildcard import silently shadows the metadata one, and every version-string f-string in make_banner() breaks with TypeError: version() takes 0 positional arguments but 1 was given.

This doesn't reproduce with the currently pinned dependency versions (confirmed: current spatialmath.base has no version export) — that's exactly what made it easy to miss. The bug is dormant, not fixed, and could silently reappear on a future spatialmath-python release. Aliasing the import (version as pkg_version) removes the name clash regardless of what any wildcard-imported module exports, now or later.

Also supersedes the still-open PR #27, which attempts the same fix but is stale against the current rvctool.py (predates its --test/Open3D rewrite) and has its own bugs (duplicate import, mislabels spatialgeometry's version with spatialmath-python's value).

Test plan

rvctool.py imports version from importlib.metadata, then later does
`from spatialmath.base import *`. If spatialmath.base ever exports its
own `version` symbol, the wildcard import silently shadows the metadata
one, and every f"...=={version(pkg)}" call in make_banner() breaks with
TypeError: version() takes 0 positional arguments but 1 was given.

This isn't hypothetical -- it's issue #26, hit by several users on an
earlier spatialmath-python release that did export such a symbol. It
doesn't reproduce with the currently pinned dependency versions, which
is exactly what made it easy to miss: the bug is dormant, not fixed.

Aliasing the import (`version as pkg_version`) removes the name clash
entirely, regardless of what any wildcard-imported module exports now
or in the future.

Fixes #26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rcvtool TypeError: version() takes 0 positional arguments but 1 was given

1 participant