Skip to content

[3.13] gh-138772: Add tests for Turtle.dot() signature (GH-138773) - #140992

Merged
hugovk merged 6 commits into
python:3.13from
JanEricNitschke:backport-2462807-3.13
Nov 5, 2025
Merged

[3.13] gh-138772: Add tests for Turtle.dot() signature (GH-138773)#140992
hugovk merged 6 commits into
python:3.13from
JanEricNitschke:backport-2462807-3.13

Conversation

@JanEricNitschke

@JanEricNitschkeJanEricNitschke commented Nov 4, 2025

Copy link
Copy Markdown
Contributor

(cherry picked from commit 2462807)

Wasnt 100% sure how to best do this, because all of the TestTurtleScreen and TestTurtle tests didn't exist at all in 3.13. So i just chose the simples way and clicked "accept incoming" on the resolution which added all tests in these classes because i think it makes sense. And obviously added the required imports.

Or should i keep it to the absolutely minimal changes and only do

classTestTurtle(unittest.TestCase):
defsetUp(self):
withpatch_screen():
self.turtle=turtle.Turtle()
# Reset the Screen singleton to avoid reference leaksself.addCleanup(setattr, turtle.Turtle, '_screen', None)
deftest_dot_signature(self):
self.turtle.dot()
self.turtle.dot(10)
self.turtle.dot(size=10)
self.turtle.dot((0, 0, 0))
self.turtle.dot(size=(0, 0, 0))
self.turtle.dot("blue")
self.turtle.dot("")
self.turtle.dot(size="blue")
self.turtle.dot(20, "blue")
self.turtle.dot(20, "blue")
self.turtle.dot(20, (0, 0, 0))
self.turtle.dot(20, 0, 0, 0)
withself.assertRaises(TypeError):
self.turtle.dot(color="blue")
self.assertRaises(turtle.TurtleGraphicsError, self.turtle.dot, "_not_a_color_")
self.assertRaises(turtle.TurtleGraphicsError, self.turtle.dot, 0, (0, 0, 0, 0))
self.assertRaises(turtle.TurtleGraphicsError, self.turtle.dot, 0, 0, 0, 0, 0)
self.assertRaises(turtle.TurtleGraphicsError, self.turtle.dot, 0, (-1, 0, 0))
self.assertRaises(turtle.TurtleGraphicsError, self.turtle.dot, 0, -1, 0, 0)
self.assertRaises(turtle.TurtleGraphicsError, self.turtle.dot, 0, (0, 257, 0))
self.assertRaises(turtle.TurtleGraphicsError, self.turtle.dot, 0, 0, 257, 0)

…H-138773)
(cherry picked from commit 2462807)
Co-authored-by: Jan-Eric Nitschke <47750513+JanEricNitschke@users.noreply.github.com>
@hugovk

Copy link
Copy Markdown
Member

Let's keep it minimal and just add test_dot_signature in the TestTurtle class, along with any setup/mocks/imports needed.

It can be another decision whether to backport all the other stuff.

@JanEricNitschke

Copy link
Copy Markdown
ContributorAuthor

Should be ready now

Comment threadLib/test/test_turtle.py Outdated
Comment threadLib/test/test_turtle.py Outdated
Comment threadLib/test/test_turtle.py Outdated
JanEricNitschkeand others added 2 commits November 4, 2025 17:02
Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com>

@hugovkhugovk left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you!

Comment on lines +509 to +515
self.turtle.dot(size="blue")
self.turtle.dot(20, "blue")
self.turtle.dot(20, "blue")
self.turtle.dot(20, (0, 0, 0))
self.turtle.dot(20, 0, 0, 0)
with self.assertRaises(TypeError):
self.turtle.dot(color="blue")

@adorilsonadorilsonNov 4, 2025

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These lines

self.turtle.dot(size="blue")

and

withself.assertRaises(TypeError):
self.turtle.dot(color="blue")

are surprising.

I've tested these and it worked as here, but it doesn't make sense.
And the docs say size is an integer, and color is a color string, as expected.
Is it a bug, alright?

(just checked before open a new issue)

@JanEricNitschkeJanEricNitschkeNov 5, 2025

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Yeah, it is a bit weird, but the actual logic is:

defdot(self, size=None, *color):
"""Draw a dot with diameter size, using color. Optional arguments: size -- an integer >= 1 (if given) color -- a colorstring or a numeric color tuple Draw a circular dot with diameter size, using color. If size is not given, the maximum of pensize+4 and 2*pensize is used. Example (for a Turtle instance named turtle): >>> turtle.dot() >>> turtle.fd(50); turtle.dot(20, "blue"); turtle.fd(50) """ifnotcolor:
ifisinstance(size, (str, tuple)):
color=self._colorstr(size)
size=self._pensize+max(self._pensize, 4)
else:
color=self._pencolorifnotsize:
size=self._pensize+max(self._pensize, 4)
else:
ifsizeisNone:
size=self._pensize+max(self._pensize, 4)
color=self._colorstr(color)

And the correct matching typehint is

@overloaddefdot(self, size: int|_Color|None=None) ->None: ...
@overloaddefdot(self, size: int|None, color: _Color, /) ->None: ...
@overloaddefdot(self, size: int|None, r: float, g: float, b: float, /) ->None: ...

The signature from the docs is

turtle.dot()
turtle.dot(size)
turtle.dot(color, /)
turtle.dot(size, color, /)
turtle.dot(size, r, g, b, /)

This makes it pretty clear the "color" is not a keyword arg, so (color="blue") shouldnt, work. But to make ("blue") and (20) work you have to have (size="blue") be valid, even though is probably isnt desired or recommended.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I've opened an issue concerning size="blue": #141062

@hugovk
hugovk merged commit 15db242 into python:3.13Nov 5, 2025
41 checks passed
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

skip newstestsTests in the Lib/test dir

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

@JanEricNitschke@hugovk@adorilson