Skip to content

Add strict typing across package, enable mypy in pre-commit#19

Merged
Joschi3 merged 4 commits into
mainfrom
feature/improved_typing
May 5, 2026
Merged

Add strict typing across package, enable mypy in pre-commit#19
Joschi3 merged 4 commits into
mainfrom
feature/improved_typing

Conversation

@Joschi3
Copy link
Copy Markdown
Owner

@Joschi3 Joschi3 commented May 5, 2026

Summary

  • Annotate the full package_xml_validation package (validation pipeline, formatter, rosdep validator, helpers, entrypoint) and introduce an XmlElement TypeAlias for lxml elements.
  • Isolate the untyped rosdep2 dependency behind a new helpers/rosdep_wrapper.py so the rest of the codebase has a single, typed boundary. Lazy imports inside the wrapper preserve existing test patches and sys.modules swaps.
  • Enable strict mypy in pyproject.toml and add a mypy hook in .pre-commit-config.yaml. Per-module ignore_missing_imports is scoped to rosdep2.*, argcomplete.*, regex, and the helpers.* script-mode fallback — so a missing stub for any other dep still surfaces as a real error.
  • Fix the latent bugs mypy surfaced:
    • None-text sorted() crashes and reused-name type drift in pkg_xml_formatter.py
    • shadowed except-var in verify_rosdep_mapping.py
    • export narrowing in BuildTypeExportStep (validation_steps.py)
    • widen LaunchDependencyStep.package_name to str | None to match formatter.get_package_name()'s return type
    • initialize PackageXmlValidator.rosdep_validator to None up-front and narrow with explicit checks before passing to dependent steps
  • Update the verify-rosdep-map hook to invoke python3 -m package_xml_validation.helpers.verify_rosdep_mapping so the new package-relative import in rosdep_wrapper resolves.
  • Add dev optional-dependencies group (mypy, types-PyYAML, lxml-stubs) for local setup.

Joschi3 added 3 commits May 4, 2026 23:50
…-win type hints

- Add helpers/rosdep_wrapper.py as the single typed boundary around rosdep2;
  lazy imports preserve existing test patches and sys.modules swaps
- Route rosdep_validator and verify_rosdep_mapping through the wrapper
- Add XmlElement TYPE_CHECKING alias in package_types.py for future lxml typing
- Annotate remaining functions in cmake_parsers, find_launch_dependencies,
  workspace, and logger so those modules are 100% typed
…oint

- Add type hints to all functions in validation_steps, pkg_xml_formatter,
  rosdep_validator, package_xml_validator, and verify_rosdep_mapping
- Use XmlElement alias (now a proper TypeAlias) consistently for lxml
  elements; isolate untyped argcomplete import behind a single ignore
- Widen LaunchDependencyStep.package_name to str | None to match
  formatter.get_package_name()'s return type
- Initialize PackageXmlValidator.rosdep_validator to None up-front and
  narrow with explicit checks before passing to dependent steps
- Add [tool.mypy] config + dev extras in pyproject.toml (strict; per-module
  ignore_missing_imports for rosdep2, argcomplete, regex, helpers.*)
- Add mypy hook to .pre-commit-config.yaml (CI picks it up automatically)
- Fix latent bugs surfaced by mypy: None-text sorted() crashes and
  reused-name type drift in pkg_xml_formatter; shadowed except-var in
  verify_rosdep_mapping; export narrowing in BuildTypeExportStep
- Fix verify-rosdep-map hook to invoke as a module so the new
  rosdep_wrapper relative import resolves
@Joschi3 Joschi3 self-assigned this May 5, 2026
Bring per-package dependency exception support (#18) into the typing
branch. Conflicts touched the two files where the typing pass overlapped
with the new 'exceptions' parameter
@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 94.54545% with 9 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
package_xml_validation/package_xml_validator.py 70.00% 6 Missing ⚠️
...ackage_xml_validation/helpers/pkg_xml_formatter.py 98.27% 1 Missing ⚠️
package_xml_validation/helpers/rosdep_validator.py 95.23% 1 Missing ⚠️
package_xml_validation/helpers/rosdep_wrapper.py 95.65% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@Joschi3 Joschi3 merged commit a1d5aa7 into main May 5, 2026
2 checks passed
@Joschi3 Joschi3 deleted the feature/improved_typing branch May 5, 2026 14:46
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