Skip to content

shlex.push_source() fails to reset lexer state, causing new stream to be ignored if called after EOF #140950

@T90REAL

Description

@T90REAL

Bug report

Bug description:

Calling shlex.push_source() after the current input has reached EOF leaves the lexer in state == None, so the newly pushed source is never read. Subsequent get_token() calls immediately return EOF instead of consuming the new input.

from shlex import shlex

lexer = shlex('a')
print(lexer.get_token())
print(lexer.get_token())  # EOF -> state is None

lexer.push_source('b', None)
print(lexer.get_token())  # actural '' (EOF), expected: 'b'
a


CPython versions tested on:

3.12

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibStandard Library Python modules in the Lib/ directorytype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions