Type checking with mypy

Aperta
#676 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
42/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python
Ambito
ci-cd, tooling

Direzione di ricerca

Esamina il marker py.typed proposto, i risultati di mypy in launch/launch/event_handler.py e launch/frontend/parser.py e i controlli CI esistenti che usano ament_pep257. Inizia verificando come ament_mypy potrebbe integrarsi nella configurazione di test attuale. Il lavoro sarà considerato completato quando l’ambito concordato del controllo dei tipi sarà implementato e CI lo verificherà senza gli errori segnalati.

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

Descrizione

help wanted

Bug report

I am sorry to open an issue in such short order, but as part of my work at Woven Planet, I'm trying to use the ROS2 launch system. Unfortunately, I have found that it type information is currently unusable from an external package, thus I'd like to improve it.

Required Info:

  • Operating System:
    • Ubuntu 18.04
  • Installation type:
    • Source
  • Version or commit hash:
    • 6783ca8
  • DDS implementation:
    • CycloneDDS
  • Client library (if applicable):
    • N/A
Steps to reproduce issue
  1. Create a snippet with this content:
import launch

context = launch.LaunchContext()
reveal_type(context)
  1. Install mypy
  2. Run the following:
MYPYPATH=$PATH_TO_WS/install/launch/lib/python3.8/site-packages/ mypy -m launch

(mypy does not use PYTHONPATH by default)

Expected behavior
test.py:4: note: Revealed type is 'launch.launch_context.LaunchContext'
Actual behavior
test.py:1: error: Cannot find implementation or library stub for module named 'launch'
test.py:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
test.py:4: note: Revealed type is 'Any'

Feature request

Feature description

I'd like to make the type checking in launch (and potentially other ROS2 core libraries) a little bit stricter. This would allow to enforce a quality standard, and root out bugs at the base. It would also make the code easier to use from the outside, since type checking would prevent some common bugs in launch files, such as using a substitution where a condition is expected. Since type-checking is strictly opt-in, there would be no impact on the broader community.

Implementation considerations
  • I have already implemented adding the py.typed file to mark the launch package as typed to the broader system, and can submit a PR promptly
  • However, there are many type-checking issues in the current codebase, including bugs. For example, mypy reported that this function does not have a return statement, contradicting its signature. Similarly, this statement has invalid type syntax. Probably someone meant Tuple? In total mypy reports 224 errors in 47 files.
  • Thus, I think we should also add a CI test to check the type information using mypy. This is I think very straightforward using ament_mypy in the same way that you are currently using ament_pep257 and others.

I can take care of the above points, but I'd like to make sure that the maintainers agree with this approach before making a PR full of tiny changes.

Thank you very much!

Lingua principale
Python
Stelle
156
Fork
200
Merge medio
2g 11h
PR unite (30g)
11

Preparare l'ambiente

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/launch

Tutte le issue di ros2/launch

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.