Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gh-126399 minor changes in RawTurtle.clone() method #126401

Open
wants to merge 41 commits into
base: main
Choose a base branch
from

Conversation

Chaebin-Kim24
Copy link

@Chaebin-Kim24 Chaebin-Kim24 commented Nov 4, 2024

This is a minor change of RawTurtle.clone() method to correct self.items of the cloned Turtle.

In clone() method, regarding items and currentLineItem,

  • First, self.currentLineItem is updated to a new one, and the item is appended to self.items by self._newLine(self._drawing)
  • Then, deepcopy of self is performed by q = self.deepcopy()
  • Finally, q.currentLineItem is updated to a new one by q.currentLineItem = screen._createline()

Potential problems of this code is that

  • updated self.currentLineItem is in q.items, so q.clear() deletes the new self.currentLineItem
  • q.currentLineItem is not in q.items, so q.clear() never deletes the q.currentLineItem

To address these issues, following changes were made.

  • update self.currentLineItem after performing deepcopy
  • append q.currentLineItem to q.items

Update RawTurtle.clone() method.

1) moved self._newLine(self._drawing) after deepcopy()
2) added q.items.append(q.currentLineItem) after q.currentLineItem = screen._createline()

Reason for 1):
When clear method is called on the cloned Turtle object, the method also deletes the first line of the original Turtle object which is drawn after cloning.

Reason for 2):
When clear method is called on the cloned Turtle object, the method does not delete the first line of the cloned Turtle object which is drawn after cloning
Copy link

cpython-cla-bot bot commented Nov 4, 2024

All commit authors signed the Contributor License Agreement.
CLA signed

@bedevere-app
Copy link

bedevere-app bot commented Nov 4, 2024

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@bedevere-app
Copy link

bedevere-app bot commented Nov 4, 2024

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

Copy link
Member

@terryjreedy terryjreedy left a comment

Choose a reason for hiding this comment

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

  1. Fix the doctest failure (see comment). DONE
  2. Add a unittest that fails without the patch and passes with it.

EDIT: I thought of expanding the doc clone example to make it a true test, but it might require too much for readers.

I am not very familiar either with doctest or the turtle code. So not likely to make a final decision and merge.

Lib/turtle.py Outdated Show resolved Hide resolved
@bedevere-app
Copy link

bedevere-app bot commented Nov 5, 2024

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

moved self._newLine(self._drawing) to original position

changed q.items.append(q.currentLineItem) to q.items[-1] = q.currentLineItem
Lib/turtle.py Outdated Show resolved Hide resolved
Lib/turtle.py Outdated Show resolved Hide resolved
@terryjreedy
Copy link
Member

I added some info relevant to testing on the issue. I still need to play around with example on issue, but am done for today.

added a unit test that fails without the patch and passes with it
revert change
TestRawTurtle.test_clone():

copied screen from TestTurtleScreen.test_save_raises_if_wrong_extension
TestRawTurtle.test_clone():

screen = Screen() as in Turtle class
Screen belongs to turtle namespace
check variable name
handling _tkinter.TclError
correct qualified name of TclError
raise SkipTest to skip test instead of skipTest()
correct qualified name of unittest.case.SkipTest exception class
lint: remove trailing whitespaces
@Chaebin-Kim24
Copy link
Author

I added a unit test for the items of cloned turtle.

This test passes with the patch.

I still need to confirm that the test fails without the patch.

@Chaebin-Kim24
Copy link
Author

Chaebin-Kim24 commented Nov 23, 2024

The same test is confirmed to fail without the patch in #127189.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants