Unexpected behavior of clear() after clone() in turtle.py module
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 77.2k
- フォーク
- 35.9k
- PR マージ指標
- PR 指標を取得中
説明
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 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.
from turtle import *
t1 = Turtle()
t2 = t1.clone()
t1.forward(100)
t2.right(90)
t2.forward(100)
t2.clear()
I 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.
I 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.
from turtle import *
#t1.currentLineItem, t1.items, t2.currentLineItem, t2.items
t1 = Turtle() #1, [1], None, None
t2 = t1.clone() #2, [1,2], 3, [1,2]
t1.forward(100) #2, [1,2], 3, [1,2]
t2.right(90) #2, [1,2], 3, [1,2]
t2.forward(100) #2, [1,2], 3, [1,2]
t2.clear() #2, [1,2], 4, [4]
So, 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.
I think that the items of the cloned Turtle should be [1,3] instead of [1,2] after clone() is called.
CPython versions tested on:
3.12
Operating systems tested on:
Windows
Linked PRs
- gh-126401
- gh-127189
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず turtle.py の clone()、clear()、forward() の定義から始め、次に issue の t1/t2 の例を再現し、関連する PR gh-126401 と gh-127189 を確認します。クローンされた Turtle が元の Turtle の軌跡を消去せずに、自身の描画を追跡して消去できれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- computer-graphics
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- 明確に書かれている
- 初心者へのやさしさ
- 25/100