python / python/cpython

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

Open
#140,950 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

stdlib type-bug
Dominant language
Python
Stars
77.2k
Forks
35.9k
PR merge metrics
PR metrics pending

Description

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

Linked PRs
  • gh-144560
  • gh-150172

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the shlex.shlex entry point and reproduce the reported sequence: consume the initial input to EOF, call push_source('b', None), then read the next token. Done means the newly pushed source is consumed instead of returning EOF; add or update regression coverage for this sequence and run the relevant shlex tests.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.