Skip to content

refactor(base): collapse the three-way Python-version type shim into one file - #212

Open
petercorke wants to merge 1 commit into
rai-opensource:masterfrom
petercorke:refactor/collapse-types-shim
Open

refactor(base): collapse the three-way Python-version type shim into one file#212
petercorke wants to merge 1 commit into
rai-opensource:masterfrom
petercorke:refactor/collapse-types-shim

Conversation

@petercorke

Copy link
Copy Markdown
Collaborator

Summary

Step 1 of a broader type-hint cleanup pass (cc @jbarry-bdai — following on from our email thread on this). Opening this narrow, mechanical piece first to get it moving while the rest gets scoped out.

spatialmath/base/types.py dispatched on sys.version_info across three duplicate files (_types_35.py, _types_39.py, _types_311.py, ~465 lines total), from when Python 3.5-3.10 support coexisted. pyproject.toml has required >=3.10 since #186, so _types_35.py could never actually be reached, and _types_39/_types_311 differed only in where Self is imported from (typing_extensions vs typing). This collapses all three into a single ~170-line file with a two-line version check. No aliases or exported names changed — purely a dedup, verified by a full test suite pass (343 passed).

What's next

This is deliberately the smallest, lowest-risk slice. A quick survey of the rest of the package turned up the following, to be tackled in follow-up PRs:

  • Annotation coverage is uneven. 838 functions/methods surveyed across spatialmath/ and spatialmath/base/: 57.5% fully annotated overall. Most of base/ is in decent shape (72-96%), but animate.py is only 6% annotated. Top-level is weaker — pose2d.py, spatialvector.py, and twist.py are all at 0%.
  • Old-style typing syntax is still widespread. Optional[X], Union[X, Y], List[X] etc. appear ~400+ times across the package (heaviest in graphics.py at 124 occurrences) and can move to X | None / X | Y / list[X] now that 3.10+ is the floor.

Planned sequencing: this shim collapse, then a mechanical syntax-modernization pass, then filling the real coverage gaps (twist.py/spatialvector.py/pose2d.py first, then animate.py) as their own PR(s) since those need actual thought rather than find-replace.

…one file

spatialmath/base/types.py dispatched on sys.version_info across
_types_35.py, _types_39.py and _types_311.py, from when Python 3.5-3.10
support coexisted. pyproject.toml has required Python >=3.10 since rai-opensource#186,
so _types_35.py could never be reached, and _types_39/_types_311 differed
only in where Self is imported from. Collapse to a single file with a
two-line version check; no change to the names or aliases it exports.
@codecov-commenter

Copy link
Copy Markdown

⚠️ Please install the 'codecov app svg image' to ensure uploads and comments are reliably processed by Codecov.

Codecov Report

❌ Patch coverage is 97.95918% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
spatialmath/base/types.py 97.95% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

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.

2 participants