Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

gh-91167: Fix cloned turtle pen not clearing completely#145406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
yukarikaname wants to merge1 commit intopython:main
base:main
Choose a base branch
Loading
fromyukarikaname:main
Open
Show file tree
Hide file tree
Changes fromall commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletionsLib/test/test_turtle.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -671,6 +671,21 @@ def test_dot_signature(self):
self.assertRaises(turtle.TurtleGraphicsError, self.turtle.dot, 0, (0, 257, 0))
self.assertRaises(turtle.TurtleGraphicsError, self.turtle.dot, 0, 0, 257, 0)

def test_clone_clear_does_not_delete_source_items(self):
screen = self.turtle.screen
screen._delete.reset_mock()
screen._createline.side_effect = lambda: object()

self.turtle.circle(20)
clone = self.turtle.clone()
source_items = set(self.turtle.items)

clone.forward(50)
clone.clear()

deleted_items = {call.args[0] for call in screen._delete.call_args_list}
self.assertFalse(source_items & deleted_items)

Comment on lines +674 to +688
Copy link

CopilotAIMar 2, 2026

Choose a reason for hiding this comment

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

This test only asserts thatclone.clear() doesn’t delete items fromself.turtle.items, but the bug class here also involves other clone-owned collections (notablystampItems andundobuffer) that can still contain source-owned canvas ids afterdeepcopy(). Extending the test to cover stamps (e.g., sourcestamp() thenclone.clear()/clearstamps()) and undo behavior (e.g.,clone.undo() doesn’t touch source drawings) would prevent regressions onceclone() is updated to reinitialize those fields too.

Copilot uses AI. Check for mistakes.
class TestModuleLevel(unittest.TestCase):
def test_all_signatures(self):
import inspect
Expand Down
2 changes: 2 additions & 0 deletionsLib/turtle.py
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -2879,6 +2879,8 @@ def clone(self):
q.turtle._item = [screen._createpoly() for item in
screen._shapes[self.turtle.shapeIndex]._data]
q.currentLineItem = screen._createline()
q.currentLine = [q._position] if q._drawing else []
q.items = [q.currentLineItem]
Copy link

CopilotAIMar 2, 2026

Choose a reason for hiding this comment

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

clone() still leaves other screen-item ownership state pointing at the source turtle:drawingLineItem is deep-copied (so animated motion can reuse the source’s transient line item),stampItems is deep-copied (soclone.clear()/clearstamps() can delete stamps created by the source), andundobuffer is deep-copied (soclone.undo() can replay/delete the source’s canvas items). Consider reinitializing these fields forq (and resetting any fill-related item ids like_fillitem/_fillpath if filling) so the clone can’t mutate/delete the source turtle’s canvas items via non-clear() operations.

Suggested change
q.items= [q.currentLineItem]
q.items= [q.currentLineItem]
# Reset ownership/undo state so the clone cannot affect the source
# turtle's existing canvas items via non-clear operations.
# The transient animation line item will be recreated on demand.
ifhasattr(q,"drawingLineItem"):
q.drawingLineItem=None
# The clone should start with no stamps of its own.
ifhasattr(q,"stampItems"):
q.stampItems= []
# Clear the clone's undo history so q.undo() cannot replay or
# delete items created before cloning.
ifhasattr(q,"undobuffer"):
reset=getattr(q.undobuffer,"reset",None)
ifcallable(reset):
reset()
# If a fill operation is active on the source, avoid sharing the
# same fill item/path ids with the clone.
ifhasattr(q,"_fillitem")andgetattr(self,"_fillitem",None)isnotNone:
q._fillitem=None
ifhasattr(q,"_fillpath")andgetattr(self,"_fillitem",None)isnotNone:
q._fillpath= []

Copilot uses AI. Check for mistakes.
q._update()
return q

Expand Down
1 change: 1 addition & 0 deletionsMisc/ACKS
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1582,6 +1582,7 @@ Sean Reifschneider
Michael P. Reilly
Bernhard Reiter
Steven Reiz
Yuxing Ren
Roeland Rengelink
Antoine Reversat
Flávio Ribeiro
Expand Down
Loading

[8]ページ先頭

©2009-2026 Movatter.jp