Confusing error message when options for `python` are erroneously quoted
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
Bug report
Bug description:
#!/bin/python -q -i
I was writing an unrelated post about shebang lines tricks+tips, and happened to pick python as an example, only to discover some weird behavior. The above gets parsed as /bin/python "-q -i" <path/to/script>
But the message python prints is quite confusing:
Unknown option: -
usage: python [option] ... [-c cmd | -m mod | file | -] [arg] ...
Try `python -h' for more information.
What's happening is that the "unknown option" is a single space, being parsed as a short-form option, and printed. But the output is pretty opaque, since the space is not quoted, and it's just a trailing invisible space.
Aside: Several other invalid one-byte options like \n get printed wrongly. This doesn't seem worth fixing.
Proposed fix:
I think the shebang case happens to users often enough that it would be good to have some kind of better error message if a short-form options list contains either of
-(this would require scanning ahead!), which either indicates some quoting problem, or an incorrect long-form option (-check-hash-based-pycsrather than--check-hash-based-pycs).
I think a good error message could be unknown option: -q -i or unknown option: "-q -i". Quoting the argument when it contains a space seems clearer to me.
The current long-form options have pretty clear error messages either way, mostly by happenstance.
Currently, -help-* parses as -h which then prints help, stopping option parsing. I have no strong opinion about whether that behavior is better or worse than printing an error message.
CPython versions tested on:
3.13
Operating systems tested on:
Linux
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
Reproduce la invocación de shebang indicada /bin/python -q -i e inspecciona el análisis de opciones de línea de comandos de CPython y los puntos de entrada para la notificación de errores. Concéntrate en cómo una cadena de opciones entre comillas se convierte en una opción de forma corta y, después, verifica que el diagnóstico resultante identifique visiblemente el argumento no válido sin cambiar el comportamiento de opciones no válidas de un byte no relacionadas.
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
- 35/100