stugen ignores and hides import errors despite not using `--ignore-errors`
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 20.6k
- Forks
- 3.3k
- Merge medio
- 1 d 18 h
- PR fusionados (30 d)
- 54
Descripción
Bug Report
The stubgen CLI currently ignores import errors even though it is not executed with --ignore-errors, setting a 0 return code despite broken usage.
To Reproduce
Simply via the CLI:
$ stubgen -p non_existing_package
# or
$ stubgen -m non_existing_module
Expected Behavior
Ideally stubgen should:
- set a non-zero exit code to indicate that something went wrong.
- show the output of what went wrong, i.e., the error that
python -c "import ..."would show. See motivation below, why this is desired.
Only if executed with --ignore-errors the return code should be 0.
Actual Behavior
stubgen prints:
non_existing_package: Failed to import, skipping
and returns "successfully" with return code 0.
Your Environment
- Mypy version used: 1.8.0
- Mypy command-line flags: none
- Mypy configuration options from
mypy.ini(and other config files): none - Python version used: Python 3.10
Issue context
This issue looks like a regression, because it was already raised ~5 years ago in https://github.com/python/mypy/issues/6794 (even Guido van Rossum ran into it) and fixed in #6804.
Motivation for printing what went wrong
The motivation for setting a non-zero exit code in case of an error should be obvious.
The motivation for "showing what actually went wrong" is as follows: The case of stubgen -p non_existing_module is of course boring, because the reason what goes wrong in this case is obvious. But the issue can be more subtle. Imaging for instance a broken pybind11 library, for which we want to generate the stubs. Pybind11 performs certain sanity checks like name collisions at import time. These error information is crucial for actually fixing the problem. Doing python -c "import my_broken_native_module" shows the actual error cause like:
Traceback (most recent call last):
File "<string>", line 1, in <module>
ImportError: generic_type: cannot initialize type "FooBar": an object with that name is already defined
Currently the stubgen swallows this key information, and just says Failed to import, skipping. This makes it tedious to analyze such an issue, because one has to manually re-run the import to see why it failed to import. From a UX perspective it would be much nicer to directly see what went wrong.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza en el punto de entrada de la CLI de stubgen y reproduce los comandos -p y -m con un módulo inexistente; después, compáralos con --ignore-errors. Traza cómo se notifican los fallos de importación y cómo se elige el estado de salida del proceso. Se considera terminado cuando las importaciones fallidas muestran su error subyacente y devuelven un estado distinto de cero de forma predeterminada, mientras que --ignore-errors conserva un estado cero.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- cli
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 55/100