Skip to content

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

Merged
StanFromIreland merged 2 commits into
python:mainfrom
StanFromIreland:turtle/undo-bugs
Oct 2, 2026
Merged

StanFromIreland merged 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!

@StanFromIreland
StanFromIreland merged commit 9d3b0b8 into python:main Oct 2, 2026
51 checks passed
@StanFromIreland
StanFromIreland deleted the turtle/undo-bugs branch October 2, 2026 16:45
@StanFromIreland StanFromIreland added needs backport to 3.14 bugs and security fixes needs backport to 3.15 pre-release feature fixes, bugs and security fixes labels Oct 2, 2026
@miss-islington-app

Copy link
Copy Markdown

Thanks @StanFromIreland for the PR 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@miss-islington-app

Copy link
Copy Markdown

Thanks @StanFromIreland for the PR 🌮🎉.. I'm working now to backport this PR to: 3.14.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Oct 2, 2026

Copy link
Copy Markdown

GH-158609 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 pre-release feature fixes, bugs and security fixes label Oct 2, 2026
@bedevere-app

bedevere-app Bot commented Oct 2, 2026

Copy link
Copy Markdown

GH-158610 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.14 bugs and security fixes label Oct 2, 2026
StanFromIreland added a commit that referenced this pull request Oct 2, 2026
…8564) (#158610)

(cherry picked from commit 9d3b0b8)

Co-authored-by: Stan Ulbrych <stan@python.org>
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