Title: Unexpected behavior of clear() after clone() in turtle.py module · Issue #126399 · python/cpython · GitHub
Open Graph Title: Unexpected behavior of clear() after clone() in turtle.py module · Issue #126399 · python/cpython
X Title: Unexpected behavior of clear() after clone() in turtle.py module · Issue #126399 · python/cpython
Description: Unexpected behavior report Unexpected behavior description: Hello, I recently started teaching Python. I found turtle module interesting and I'm planning to use the module for deeper understanding of loop, condition, and function. I trie...
Open Graph Description: Unexpected behavior report Unexpected behavior description: Hello, I recently started teaching Python. I found turtle module interesting and I'm planning to use the module for deeper understanding ...
X Description: Unexpected behavior report Unexpected behavior description: Hello, I recently started teaching Python. I found turtle module interesting and I'm planning to use the module for deeper understand...
Opengraph URL: https://github.com/python/cpython/issues/126399
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Unexpected behavior of clear() after clone() in turtle.py module","articleBody":"# Unexpected behavior report\r\n\r\n### Unexpected behavior description:\r\n\r\nHello, I recently started teaching Python. I found turtle module interesting and I'm planning to use the module for deeper understanding of loop, condition, and function. I tried to simplify some turtle examples, just to show how for loop works. I cloned Turtle object, moved the clones to initial position, and cleared all Turtles before start drawing. However, clear() method did not work as I expected. Here is the code that I used.\r\n\r\n```python\r\nfrom turtle import *\r\n\r\nt1 = Turtle()\r\nt2 = t1.clone()\r\n\r\nt1.forward(100)\r\nt2.right(90)\r\nt2.forward(100)\r\n\r\nt2.clear()\r\n```\r\n\r\nI expected t2.clear() to clear the trace of the cloned Turtle. Instead, t2.clear() erased the trace of the original Turtle, where the trace was drawn after the cloning. \r\n\r\nI wanted to know what is going on, so I read the definition of clear() method, and the method seemed to delete all items in self.items. Also, the source code of forward() used self.currentLineItem when drawing. So I tracked items and currentLineItem in my code. Here are the results of the tracking.\r\n\r\n```python\r\nfrom turtle import *\r\n\r\n#t1.currentLineItem, t1.items, t2.currentLineItem, t2.items\r\n\r\nt1 = Turtle() #1, [1], None, None\r\n\r\nt2 = t1.clone() #2, [1,2], 3, [1,2]\r\n\r\nt1.forward(100) #2, [1,2], 3, [1,2]\r\nt2.right(90) #2, [1,2], 3, [1,2]\r\nt2.forward(100) #2, [1,2], 3, [1,2]\r\n\r\nt2.clear() #2, [1,2], 4, [4]\r\n```\r\n\r\nSo, t2 drew lines in _**3**_, however, because _**3**_ is not in t2.items, t2.clear() does not delete _**3**_. Also, t1 drew lines in _**2**_, and, because _**2**_ is in t2.items, t2.clear() delete _**2**_.\r\n\r\nI think that the items of the cloned Turtle should be _**[1,3]**_ instead of _**[1,2]**_ after clone() is called.\r\n\r\n### CPython versions tested on:\r\n\r\n3.12\r\n\r\n### Operating systems tested on:\r\n\r\nWindows\r\n\r\n\u003c!-- gh-linked-prs --\u003e\r\n### Linked PRs\r\n* gh-126401\r\n* gh-127189\n\u003c!-- /gh-linked-prs --\u003e\r\n","author":{"url":"https://github.com/Chaebin-Kim24","@type":"Person","name":"Chaebin-Kim24"},"datePublished":"2024-11-04T14:33:00.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":1},"url":"https://github.com/126399/cpython/issues/126399"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:8ddf3855-335d-bf9b-e1ae-70d860c338aa |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 9804:9E6E4:D58B0:13071E:696A0AD4 |
| html-safe-nonce | d8903ded1db2c159250f93c9a4dba6a2858de5415b847c93deb28f6d28bd60fe |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI5ODA0OjlFNkU0OkQ1OEIwOjEzMDcxRTo2OTZBMEFENCIsInZpc2l0b3JfaWQiOiI1NDE2NzgxNzMyOTM0OTc4MjYwIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 8c436b3651be1a8f70b5cd42baec6a6037e266d0cd3390baef9fea1332c919b4 |
| hovercard-subject-tag | issue:2632982097 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/126399/issue_layout |
| twitter:image | https://opengraph.githubassets.com/5029114c8642c4d4e9b5a8a50ad4413d22de44600afd65813985812732792a4f/python/cpython/issues/126399 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/5029114c8642c4d4e9b5a8a50ad4413d22de44600afd65813985812732792a4f/python/cpython/issues/126399 |
| og:image:alt | Unexpected behavior report Unexpected behavior description: Hello, I recently started teaching Python. I found turtle module interesting and I'm planning to use the module for deeper understanding ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Chaebin-Kim24 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 699227a00bbb7fe1eec276d2ae1c3a93068bc5ba483bd9dc4b2a27a8f4f2f595 |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 7266b2d935baa1c6474b16dd9feaa5ca30607261 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width