ros2 / ros2/launch

Type annotations do not reflect that Entity.get_attr()'s data_type parameter can be None

Open
#888 0 comments 0 reactions 1 assignee View on GitHub

@christophebedard is already working on this.

Since Jun 26, 2025.

backlog bug
Dominant language
Python
Stars
155
Forks
182
Avg merge
2d 14h
Merged PRs (30d)
6

Description

Generated by Generative AI

No response

Operating System:

all

ROS version or commit hash:

Rolling

RMW implementation (if applicable):

No response

RMW Configuration (if applicable):

No response

Client library (if applicable):

No response

'ros2 doctor --report' output

No response

Steps to reproduce issue

Run tests downstream of launch with the assumption that data_type can't be None, e.g., https://github.com/ros2/launch/pull/887#issuecomment-2987111760 for #887.

Expected behavior

Tests pass

Actual behavior

Tests fail if we assume that data_type can't be None, see these test failures for #887:

  1. https://ci.ros2.org/job/ci_linux/24014/testReport/junit/test_launch_ros.test.test_launch_ros.frontend/test_component_container/test_launch_component_container_xml/
  2. https://ci.ros2.org/job/ci_linux/24014/testReport/junit/test_launch_ros.test.test_launch_ros.frontend/test_node_frontend/test_launch_frontend_xml/
Additional information

See https://github.com/ros2/launch/pull/887#discussion_r2157614696. The type annotation for data_type in launch_xml/launch_yaml's Entity.get_attr() is AllowedTypesType, which does not include None:

  1. launch_xml: https://github.com/ros2/launch/blob/6854fae626f2948139e1734e68d712cc1e0def1b/launch_xml/launch_xml/entity.py#L79
  2. launch_yaml: https://github.com/ros2/launch/blob/6854fae626f2948139e1734e68d712cc1e0def1b/launch_yaml/launch_yaml/entity.py#L102

However, the documentation in launch's Entity.get_attr() mentions that data_type can be None, in which case it behaves like str (IIUC), which is the default data_type value: https://github.com/ros2/launch/blob/6854fae626f2948139e1734e68d712cc1e0def1b/launch/launch/frontend/entity.py#L89

Interestingly, launch's Entity.get_attr()'s type annotations are kind of incomplete, especially for data_type. They use TargetType, but that does not specify any type, and, critically, it does not specify None/Optional: https://github.com/ros2/launch/blob/6854fae626f2948139e1734e68d712cc1e0def1b/launch/launch/frontend/entity.py#L46-L76

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.