fix: alias importlib.metadata.version to avoid wildcard-import shadowing - #43
Open
petercorke wants to merge 1 commit into
Open
fix: alias importlib.metadata.version to avoid wildcard-import shadowing#43petercorke wants to merge 1 commit into
petercorke wants to merge 1 commit into
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #26.
rvctool.pyimportsversionfromimportlib.metadata, then later doesfrom spatialmath.base import *. Ifspatialmath.baseever exports its ownversionsymbol, the wildcard import silently shadows the metadata one, and every version-string f-string inmake_banner()breaks withTypeError: version() takes 0 positional arguments but 1 was given.This doesn't reproduce with the currently pinned dependency versions (confirmed: current
spatialmath.basehas noversionexport) — 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 --testbanner still reports correct versions for every packagepytest tests/test_bin.py— the only failure is the pre-existing, already-trackedvloop_testissue (PR fix: commit missing vloop_test/ploop_test model fixtures #41), unrelated to this change