Skip to content

gh-158563: Fix various bugs in turtle's undo handling - #158564

Open
StanFromIreland wants to merge 2 commits into
python:mainfrom
StanFromIreland:turtle/undo-bugs
Open

StanFromIreland wants to merge 2 commits into
python:mainfrom
StanFromIreland:turtle/undo-bugs

Conversation

@StanFromIreland

@StanFromIreland StanFromIreland commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Comment thread Lib/turtle.py Outdated
Comment thread Lib/turtle.py
Comment on lines +2812 to +2813
if was_filling and not fill_gap:
self.end_fill()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When teleport() runs during an active fill with the default fill_gap=False, its new undo sequence ends the original fill and starts another, but does not preserve the original fill state. Undoing the sequence clears the new fill through the beginfill handler without restoring the old _fillitem or _fillpath. For example, begin_fill(); forward(10); teleport(100, 100); undo() restores the position but leaves filling() false, so subsequent drawing cannot complete the original polygon.

@StanFromIreland StanFromIreland Oct 1, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is an existing bug, and it's not just for teleport. A proper fix could be for begin_fill() and end_fill() to record the fill item and path they replace in their undo entries, and undo() would restore them, so undoing either call (or a teleport() during a fill) resumes the original fill. However this would alter the number of entries in the undo buffer, so this needs to be a 3.16-only change to not break scripts that may be relying on the current number.

We can do this in a follow up to ease backporting.

@m-aciek m-aciek left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants