Skip to content

Validate iterable elements in ensure_argument_type - #993

Open
dlanov wants to merge 1 commit into
ros2:rollingfrom
dlanov:fix-109-validate-argument-types
Open

Validate iterable elements in ensure_argument_type#993
dlanov wants to merge 1 commit into
ros2:rollingfrom
dlanov:fix-109-validate-argument-types

Conversation

@dlanov

@dlanov dlanov commented Jul 30, 2026

Copy link
Copy Markdown

Fixes #109.

Summary

ensure_argument_type() accepted an iterable for its types argument without validating that every element was actually a type.

This caused two inconsistent behaviors:

  • an invalid element before a valid type exposed Python's generic isinstance() error
  • an invalid element after an already matching type could be silently ignored because any() short-circuited

This change materializes the iterable once and validates every element before performing argument matching.

Existing behavior remains unchanged for:

  • a single type
  • lists and tuples of types
  • generators and other iterables
  • inheritance checks
  • empty iterables

Testing

  • python3 -m pytest launch/test/launch/utilities/test_ensure_argument_type.py -q
  • python3 -m pytest launch/test/launch/utilities -q
  • python3 -m flake8 --config=/opt/ros/jazzy/lib/python3.12/site-packages/ament_flake8/configuration/ament_flake8.ini launch/launch/utilities/ensure_argument_type_impl.py launch/test/launch/utilities/test_ensure_argument_type.py
  • git diff --check

Results:

  • focused tests: 5 passed
  • utility tests: 38 passed
  • flake8: clean

ensure_argument_type accepted iterables without validating that every element was a type. Invalid entries could expose Python's generic isinstance error or be skipped when any() short-circuited after an earlier match.

Materialize the iterable once and validate all elements before matching, while preserving existing behavior for valid inputs and empty iterables.

Signed-off-by: Dennis Lanov <dennis.lanov@gmail.com>
@mergify

mergify Bot commented Jul 30, 2026

Copy link
Copy Markdown

Tick the box to add this pull request to the merge queue (same as @mergifyio queue).

  • Queue this pull request

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.

[launch] check that iterable contains only types in ensure_argument_type()

1 participant