Message named pkg/Duration with field builtin_interfaces/Duration is invalid

Aperta
#257 8 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
55/100
Tipo di issue
Bug
Chiarezza
Abbastanza chiara
Stato di attività
Tranquilla
Stack tecnologico
python
Ambito
tooling

Direzione di ricerca

Riproducete il problema con un pacchetto di messaggi contenente pkg/Duration e un campo builtin_interfaces/Duration, quindi esaminate l'output build/stamped_msgs/rosidl_generator_py/stamped_msgs/msg/_duration.py. Tracciate il codice del generatore che produce gli import in conflitto, aggiornate il comportamento di generazione in modo che il nome del messaggio non venga oscurato ed eseguite i controlli mypy e flake8 segnalati per confermare che il codice generato sia valido.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug
Generated by Generative AI

No response

Operating System:

Linux

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
  1. Create a message package pkg containing a message type named Duration with a field of type builtin_interfaces/Duration.
  2. Compile the workspace and inspect the generated Python code.
  3. Run mypy tests and flake8
Expected behavior

Message type pkg/Duration should be valid.

Actual behavior

The generated message Python code is invalid:

 27: /root/target_ws/build/stamped_msgs/rosidl_generator_py/stamped_msgs/msg/_duration.py:87:1: F811 redefinition of unused 'Duration' from line 20
  27: class Duration(rosidl_pycommon.interface_base_classes.BaseMessage, metaclass=Metaclass_Duration):
  27: ^
  27: 
  27: 1     F811 redefinition of unused 'Duration' from line 20
  30: /root/target_ws/build/stamped_msgs/rosidl_generator_py/stamped_msgs/msg/_duration.py:87:1: error: Name "Duration" already defined (possibly by an import)  [no-redef]
  30: /root/target_ws/build/stamped_msgs/rosidl_generator_py/stamped_msgs/msg/_duration.py: note: In member "__eq__" of class "Duration":
  30: /root/target_ws/build/stamped_msgs/rosidl_generator_py/stamped_msgs/msg/_duration.py:151:27: error: "Duration" has no attribute "header"  [attr-defined]
  30: /root/target_ws/build/stamped_msgs/rosidl_generator_py/stamped_msgs/msg/_duration.py:153:25: error: "Duration" has no attribute "data"  [attr-defined]
  30: Found 3 errors in 1 file (checked 46 source files)
Additional information

Indeed, there are multiple places in the generated code that do:

from a.msg import b

But if the message is named pkg.Duration and the type of one of its fields is builtin_interfaces.Duration, then this import shadows the actual pkg.Duration and the code gets either confused, or even invalid.

I think all usages of from a.msg import b should be replaced by import a.msg; .... a.msg.b in the generated code. This way, the name collisions would not happen.

Lingua principale
EmberScript
Stelle
26
Fork
68
Merge medio
2g 13h
PR unite (30g)
1

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di ros2/rosidl_python

Tutte le issue di ros2/rosidl_python

Issue simili

Altre issue su DevTools

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.