Skip to content

gh-133244: TPen.pensize raises TurtleGraphicsError if called with a negative number #135268

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

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

Conversation

adorilson
Copy link
Contributor

@adorilson adorilson commented Jun 8, 2025

Fix #133244.

Before

>>> import turtle
>>> turtle.pensize(-1)
>>> turtle.forward(100)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 8, in forward
  File "/home/adorilson/anaconda3/lib/python3.12/turtle.py", line 1636, in forward
    self._go(distance)
  File "/home/adorilson/anaconda3/lib/python3.12/turtle.py", line 1597, in _go
    self._goto(ende)
  File "/home/adorilson/anaconda3/lib/python3.12/turtle.py", line 3248, in _goto
    screen._drawline(self.drawingLineItem,
  File "/home/adorilson/anaconda3/lib/python3.12/turtle.py", line 543, in _drawline
    self.cv.itemconfigure(lineitem, width=width)
  File "<string>", line 1, in itemconfigure
  File "/home/adorilson/anaconda3/lib/python3.12/tkinter/__init__.py", line 2988, in itemconfigure
    return self._configure(('itemconfigure', tagOrId), cnf, kw)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/adorilson/anaconda3/lib/python3.12/tkinter/__init__.py", line 1712, in _configure
    self.tk.call(_flatten((self._w, cmd)) + self._options(cnf))
_tkinter.TclError: bad screen distance "-1"

Now

>>> import turtle
>>> turtle.pensize(-1)
Traceback (most recent call last):
  File "<python-input-1>", line 1, in <module>
    turtle.pensize(-1)
    ~~~~~~~~~~~~~~^^^^
  File "<string>", line 8, in pensize
  File "/home/adorilson/workspace/cpython/Lib/turtle.py", line 2145, in pensize
    raise TurtleGraphicsError(f"width argument must be a positive number. It was {width}.")
turtle.TurtleGraphicsError: width argument must be a positive number. It was -1.

For now, the 0 behaviour wasn't changed, but I think it would.

If we call turtle.pensize(0) it changes the width to 0, but when the turtle draws, the real line's width is 1. It seems to be a misconception. However, change could be a backwards compatibility concern. Perhaps we can schedule a change for now with a DeprecationWarning.

vstinner and others added 5 commits June 7, 2025 12:29
…#106335)

Remove private _PyThreadState and _PyInterpreterState C API
functions: move them to the internal C API (pycore_pystate.h and
pycore_interp.h). Don't export most of these functions anymore, but
still export functions used by tests.

Remove _PyThreadState_Prealloc() and _PyThreadState_Init() from the C
API, but keep it in the stable API.
This reverts commit ebfa093.
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.

Make turtle.pensize smarter
2 participants