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

Maintainers usually reply within 1 day

@christophebedard is already working on this.

Since Jun 26, 2025.

Assessment

This issue has not been assessed yet.

Description

backlog bug
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

Dominant language
Python
Stars
156
Forks
200
Avg merge
2d 11h
Merged PRs (30d)
11

Getting set up

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.

More from ros2/launch

All issues in ros2/launch

Similar issues

More Python issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.