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
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
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
Bug description:
Summary
When
shlex.shlexsource 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 bysourcehook()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
Actual behavior
The
from-childtoken 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
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