Add Python generator support for deprecated interface fields#252
Add Python generator support for deprecated interface fields#252Pengkun-ZHU wants to merge 1 commit intoros2:kiltedfrom
Conversation
Implements the Python generator side of field-level deprecation support. This PR is based on and should be merged as a companion to ros2/rosidl#945, which establishes the IDL annotation pipeline for C and C++ generators. When a message field is annotated with @deprecated(text=...) in an .idl file, the generated Python message class will: - Decorate the property getter and setter with @typing_extensions.deprecated(text) (PEP 702), enabling static analysis tools (mypy, pyright, IDEs) to flag deprecated field usage at development time - Emit a DeprecationWarning at runtime when the field is accessed or set The C extension (_msg_support.c.em) wraps internal accesses to deprecated fields with DISABLE_DEPRECATED_PUSH/POP to suppress warnings in generated conversion code. Changes: - resource/_msg.py.em: import and apply @_deprecated decorator on getter/setter when field has @deprecated annotation - resource/_msg_support.c.em: suppress deprecation warnings around internal PyObject_GetAttrString/SetAttrString calls - package.xml: add python3-typing-extensions exec_depend - CMakeLists.txt: add TestDeprecated.idl test message and test_deprecated.py regression test Signed-off-by: Pengkun-ZHU <q1091803103@gmail.com>
|
@InvincibleRMC @jmachowinski, I did a Python support following the implementation in ros2/rosidl#945. Could you help give it a review? |
|
I'll let @InvincibleRMC take a look, but FYI you should target the |
|
@Pengkun-ZHU What happens if you do equality checks? Do those emit deprecation warnings? I don't think they should. |
Nice catch, I'll make __eq__ use self._<field> instead of getter to avoid deprecation warning. Similarly I'll do it for __repr__. Any more to add? |
Duly noted with many thanks. I'll rebase and modify. |
|
Closing in favor of a new PR targeting rolling branch. |
|
New PR targeting rolling branch is filed: |
|
FYI, in the future: You can rebase your branch and then change the target branch of your PR to |
Implements the Python generator side of field-level deprecation support. This PR is based on and should be merged as a companion to ros2/rosidl#945, which establishes the IDL annotation pipeline for C and C++ generators.
When a message field is annotated with
@deprecated(text='...')in an .idl file, the generated Python message class will:@typing_extensions.deprecated(text)(PEP 702), enabling static analysis tools (mypy, pyright, IDEs) to flag deprecated field usage at development timeDeprecationWarningat runtime when the field is accessed or setThe C extension _msg_support.c.em wraps internal accesses to deprecated fields with
DISABLE_DEPRECATED_PUSH/POPto suppress warnings in generated conversion code.Related