Skip to content

Fix SourceReader.ungetc - #83

Open
hilman2 wants to merge 1 commit into
CheetahTemplate3:masterfrom
hilman2:fix-sourcereader-ungetc
Open

Fix SourceReader.ungetc#83
hilman2 wants to merge 1 commit into
CheetahTemplate3:masterfrom
hilman2:fix-sourcereader-ungetc

Conversation

@hilman2

@hilman2 hilman2 commented Aug 26, 2026

Copy link
Copy Markdown

ungetc cannot succeed under any input on master.

>>> r = SourceReader('abc'); r.getc(); r.ungetc()
Error: Already at beginning of stream

The guard is inverted, so the method raises whenever there is a character to unget. At position 0 it falls through and sets self._pos = -1, and the following self._src[self._pos] = c is an item assignment on a str.

Nothing in Cheetah calls it, so this is public API only. Three tests in Tests/Misc.py. Full suite passes on 2.7, 3.6 and 3.12, flake8 clean.

The guard reads `if not self.atStart(): raise`, so the method raised
whenever there was a character to unget. At position 0 it fell through
instead and set self._pos to -1.

Writing the character back did `self._src[self._pos] = c`, an item
assignment on a str. That is a TypeError on any Python 3, so the
method could not succeed under any input.

Nothing in Cheetah calls it; it is public API.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants