GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — gh-65276: Fixed Turtle library circle method bug by liam-gersten · Pull Request #104022 · python/cpython

Conversation

@liam-gersten

@liam-gersten liam-gersten commented Apr 30, 2023 •
edited by bedevere-bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Behavior:

Having used multiple turtle instances to create various object for an interactive Tic-Tac-Toe game, a user noticed that setting turtle speeds to 0 (instant) lead to "disappearing" objects. The bug was with the circle method, which was called on click. The user had created tiles and lines to display the "board" using multiple turtle instances, and when the circle method was called for speed 0 turtles, the board would display on top of all lines and circle drawn, effectively making them disappear.

The issue:

When setting speed to 0 in particular, the circle method would call the _tracer method to set self._tracing and self._delayvalue to zero, before drawing the circle, and then resetting both of these values via the _tracer method. The issue is in the final call to _tracer that resets the two values. This is because _tracer actually calls screen.tracer, and when resetting with a nonzero first argument, screen.tracer actually calls screen.update() on line 1272. This update method redraws EVERY turtle object that shares the current screen, which is both unnecessary in this case, and also creates the actual bug itself.

Eventually, the screen.update() method calls t._drawturtle() for every turtle, which can (and does in this case) include background turtle objects like the user's board objects. Despite it actually iterating through the turtle objects in the right order, the t._drawturtle() method tries to draw the first object on top. This takes place in multiple screen._drawpoly calls with a top=True argument. One might think top=True would behave like a stack, i.e., the most recent call like this would actually be on top. In reality, it either behaves like a queue, or just negates every call except the first. In the case of the user's code, the first-created turtle object (the board) got the screen._drawpoly(..., top=True) call first, and thus, displayed on top of all other turtle creations.

The fix:

The screen._drawpoly ends with external library code, most likely tkinter, so I won't be attempting to change its behavior. Generally, changing _drawturtle(), update, _update, tracer, or _tracer would be inappropriate for such a bug, as doing such would be a large (potentially bug-creating) alteration for such a minor bug. Because of this, the fix should be with the circle method itself.

Due to how the screen._drawpoly(..., top=True) call behaves in _drawturtle, we only actually want the call to be made for the current turtle that is drawing the circle. Unfortunately, the update method calls _drawturtle for every turtle, so we can't avoid _drawturtle calls for the turtles we don't want to draw. Fortunately, _drawturtle won't actually call screen._drawpoly(..., top=True) when self._shown = False and self._hidden_from_screen = True. These are attributes that we CAN set from the circle method for any and every turtle object on the same screen. Thus, for every other turtle sharing the screen, we save the values of these two attributes, set them so they don't get redrawn, call self._tracer, and then restore the prior attribute values for all other turtle objects.

Resolves #65276

  • Issue: Turtle Circle Speed 0 #65276

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

arhadthedev reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
liam-gersten added 3 commits April 28, 2023 12:38
@liam-gersten
Merge pull request #3 from python/main
9d1551c
Update fork
@liam-gersten
Merge pull request #6 from python/main
45f5a89
Update Fork
@liam-gersten
Save and restore fix
cac85cb
@bedevere-bot bedevere-bot mentioned this pull request Apr 30, 2023
Turtle Circle Speed 0 #65276
Open
@bedevere-bot bedevere-bot added the awaiting review label Apr 30, 2023
@blurb-it
📜🤖 Added by blurb_it.
50f4059
@arhadthedev

arhadthedev commented May 1, 2023

Copy link
Copy Markdown
Member

Azure Pipelines PR check → Ubuntu PR Tests → Run patchcheck.py reports an error.

Could you run Tools/patchcheck/patchcheck.py locally, commit changes made by the script and push them here, please?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@hugovk

hugovk commented May 1, 2023

Copy link
Copy Markdown
Member

Looks like some trailing whitespace that slipped in from #103974.

Tip: set your code editor to trim trailing whitespace on save. Or check it can read the .editorconfig file.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

liam-gersten added 2 commits May 1, 2023 12:16
@liam-gersten
Merge branch 'main' into CircleSpeed0Fix
15b71a8
@liam-gersten
Removed trailing whitespace
1ea6c22
@liam-gersten

liam-gersten commented May 1, 2023

Copy link
Copy Markdown
Contributor Author

I have made the requested changes; please review again.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bedevere-bot bedevere-bot added awaiting change review and removed awaiting review labels May 1, 2023
@bedevere-bot

bedevere-bot commented May 1, 2023

Copy link
Copy Markdown

Thanks for making the requested changes!

: please review the changes made to this pull request.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

liam-gersten added 2 commits May 1, 2023 13:29
@liam-gersten
Merge branch 'main' into CircleSpeed0Fix
901128f
@liam-gersten
Merge branch 'main' into CircleSpeed0Fix
eddd166
@arhadthedev arhadthedev added awaiting review and removed awaiting change review labels May 1, 2023
liam-gersten added 2 commits May 1, 2023 15:18
@liam-gersten
Merge branch 'main' into CircleSpeed0Fix
70ed302
@liam-gersten
Merge branch 'main' into CircleSpeed0Fix
6676795
@hugovk

hugovk commented May 3, 2023

Copy link
Copy Markdown
Member

Tip: usually there's no need to update the PR branch from main, unless there's something specific needed from there.

We can also save some CI resources and avoid triggering notifications.

liam-gersten reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions

github-actions Bot commented Apr 12, 2026

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

awaiting review stale Stale PR or inactive for long period of time.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Turtle Circle Speed 0

Uh oh!

There was an error while loading. Please reload this page.

4 participants

@liam-gersten @arhadthedev @hugovk @bedevere-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.