You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
turtle.dot(size="blue") has a weird behaviour #141062
turtle.dot()
turtle.dot(size)
turtle.dot(color, /)
turtle.dot(size, color, /)
turtle.dot(size, r, g, b, /)
Parameters:
size – an integer >= 1 (if given)
color – a colorstring or a numeric color tuple
However, turtle.dot(size="blue") doesn't raise an exception. Instead of this, the color is changed to blue.
def dot(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)
"""
if not color:
if isinstance(size, (str, tuple)):
color = self._colorstr(size)
size = self._pensize + max(self._pensize, 4)
else:
color = self._pencolor
if not size:
size = self._pensize + max(self._pensize, 4)
else:
if size is None:
size = self._pensize + max(self._pensize, 4)
color = self._colorstr(color)
Is it possible to identify if an argument was passed by position or by name?
In general, no, such information is not preserved. We could convert it to dot(*args, **kwargs) and we could then distinguish positional vs keyword, but implementing it with all of the required additional handling is quite messy, and not worth the additional complexity in this case IMO.
What about having an ad-hoc wrapper which could use *args and **kwargs (and functools.wraps to preserve the original signature), and then error on a non-numeric "size" passed by name?
I think that the simplest way to get rid of such weird behavior is to forbid passing the size argument by keyword. Yes, this is a breaking change, and normally we would need to add a complicated code that emits a deprecation warning. But it is unlikely that many code will be broke -- there is no benefit of passing size by keyword, especially if you cannot pass color by keyword.
On other hand, if nobody passes the size argument by keyword, this change would fix no code. This would be mostly cosmetic change.
Activity
[-]turtle.dot(size="blue") has a weird behaviuor[/-][+]turtle.dot(size="blue") has a weird behaviour[/+]StanFromIreland commentedon Nov 5, 2025
Intentional, however:
cpython/Lib/turtle.py
Lines 3501 to 3503 in 4ac16dd
So I shall mark this as a feature.
JanEricNitschke commentedon Nov 5, 2025
Yeah, this is the runtime code:
This is the corresponding type hint in typeshed:
And this is what the docs state (https://docs.python.org/3/library/turtle.html#turtle.dot):
I dont think there is a way to achieve the current desired behaviour without this
adorilson commentedon Nov 5, 2025
I saw this. The problem seems to be on 3502 line.
After, the
colorvariable will be used incpython/Lib/turtle.py
Lines 3520 to 3523 in 4ac16dd
I think we just need to erase the 3502 line.
JanEricNitschke commentedon Nov 5, 2025
If you want to allow all three of these
then i dont think there is a way to NOT have
adorilson commentedon Nov 5, 2025
I got your point.
Is it possible to identify if an argument was passed by position or by name?
StanFromIreland commentedon Nov 5, 2025
In general, no, such information is not preserved. We could convert it to
dot(*args, **kwargs)and we could then distinguish positional vs keyword, but implementing it with all of the required additional handling is quite messy, and not worth the additional complexity in this case IMO.jsbueno commentedon Nov 5, 2025
What about having an ad-hoc wrapper which could use *args and **kwargs (and functools.wraps to preserve the original signature), and then error on a non-numeric "size" passed by name?
serhiy-storchaka commentedon Nov 6, 2025
I think that the simplest way to get rid of such weird behavior is to forbid passing the
sizeargument by keyword. Yes, this is a breaking change, and normally we would need to add a complicated code that emits a deprecation warning. But it is unlikely that many code will be broke -- there is no benefit of passingsizeby keyword, especially if you cannot passcolorby keyword.On other hand, if nobody passes the
sizeargument by keyword, this change would fix no code. This would be mostly cosmetic change.