python / python/cpython

`shlex` silently discards a sourced stream when the source filename ends at EOF

Abierto
#156,891 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

stdlib type-bug
Lenguaje dominante
Python
Estrellas
77.2k
Forks
35.9k
Métricas de merge de PR
Métricas de PR pendientes

Descripción

Bug description:

Summary

When shlex.shlex source inclusion is enabled and the filename following the source directive is the final token in the parent input, with no trailing whitespace or newline, the stream returned by sourcehook() is opened or created normally but all of its tokens are silently discarded. The included stream is then closed.

It contradicts the documented source-inclusion semantics, under which input should be read from the included stream until EOF before parsing resumes in the parent stream.

Minimal reproducer

import io
import shlex

lexer = shlex.shlex("include child", posix=True)
lexer.source = "include"

included = io.StringIO("from-child")
lexer.sourcehook = lambda filename: (filename, included)

print(list(lexer))
print(included.closed)

Actual behavior

[]
True

The from-child token is never returned, and the included stream is closed. No exception is raised, so callers cannot detect from the token stream that included input was skipped.

Expected behavior

['from-child']
True

The included stream should be parsed completely, closed when it reaches EOF, and only then should parsing resume in the parent stream.

CPython versions tested on:

CPython main branch

Operating systems tested on:

Linux

Linked PRs
  • gh-156892

Guía de contribución

Abrir la guía de contribución

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.

Línea de trabajo

Empieza ejecutando el reproductor mínimo en Python e inspecciona en el código fuente de shlex.shlex la inclusión de fuentes alrededor de sourcehook() y el manejo del final de la entrada. Se considera terminado cuando el flujo incluido produce 'from-child' antes de cerrarse, mientras el análisis sintáctico continúa correctamente en el flujo padre.

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
Bien especificado
Aptitud para principiantes
25/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.