Type checking with mypy

Abierto
#676 4 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
5/5
Tiempo estimado
Más de una semana
Aptitud para principiantes
42/100
Tipo de issue
Nueva funcionalidad
Claridad
Bastante claro
Estado de actividad
Estancado
Stack tecnológico
python
Área
ci-cd, tooling

Línea de trabajo

Revisa el marcador py.typed propuesto, los resultados de mypy en launch/launch/event_handler.py y launch/frontend/parser.py, y las comprobaciones de CI existentes que usan ament_pep257. Empieza comprobando cómo encajaría ament_mypy en la configuración de pruebas actual. Se considerará completado cuando se haya implementado el alcance acordado de la comprobación de tipos y CI lo verifique sin los errores indicados.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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!

Lenguaje dominante
Python
Estrellas
156
Forks
200
Merge medio
2 d 11 h
PR fusionados (30 d)
11

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de ros2/launch

Todos los issues de ros2/launch

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.