Skip to content

Fix issue #1679: Add deprecation of interface variables#251

Draft
Pengkun-ZHU wants to merge 1 commit intoros2:kiltedfrom
Pengkun-ZHU:feature/field-deprecation-annotation
Draft

Fix issue #1679: Add deprecation of interface variables#251
Pengkun-ZHU wants to merge 1 commit intoros2:kiltedfrom
Pengkun-ZHU:feature/field-deprecation-annotation

Conversation

@Pengkun-ZHU
Copy link

Companion to ros2/rosidl#946 (fixes ros2/ros2#1679)

Summary

Adds DeprecationWarning support to the Python message generator for fields annotated with @deprecated.

What this changes

rosidl_generator_py/resource/_msg.py.em

For any field whose IDL Member carries a @deprecated annotation (set via # @deprecated in the .msg source), the generated Python property getter and setter now emit:

import warnings
warnings.warn(
    "field 'old_field' in 'MyMessage' is deprecated",
    DeprecationWarning,
    stacklevel=2)

This fires at runtime whenever user code reads or writes the deprecated field, following standard Python deprecation convention (stacklevel=2 points the warning at the caller, not the generated code).

Coverage

The _msg.py.em template is the single leaf template invoked for all message-like types — messages, service request/response/event sub-messages, and action goal/result/feedback sub-messages — so the warning propagates automatically to .srv and .action fields as well.

Known limitations / out of scope

  • Whole-message deprecation is not addressed here; only field-level.
  • No custom deprecation message# @deprecated carries no free-text argument in this version.
  • Wire format is unchanged@deprecated does not affect type hash or serialization.

Signed-off-by: Pengkun-ZHU <q1091803103@gmail.com>
@Pengkun-ZHU Pengkun-ZHU force-pushed the feature/field-deprecation-annotation branch from 624a621 to a30b504 Compare March 20, 2026 14:17
@Pengkun-ZHU Pengkun-ZHU marked this pull request as draft March 20, 2026 14:40
@InvincibleRMC
Copy link
Contributor

I can write my own implementation or you can update yours. Either is fine but you would have to add the deprecation push pop probably to the message.c.em. You should also use deprecation from typing_extensions. And finally use the text from the annotation some where in the message so user can know what to migrate to

@Pengkun-ZHU
Copy link
Author

Sure, I will make a further change to align with your implementation.

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