python / python/cpython

Make turtle.pensize smarter

オープン
#133,244 コメント 3 件 リアクション 1 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

stdlib type-feature
主要言語
Python
スター
77.2k
フォーク
35.9k
PR マージ指標
PR 指標を取得中

説明

Feature or enhancement

Proposal:

The turtle.pensize doc says:

turtle.pensize(width=None)
    Parameters:

        width – a positive number

However, if you put a non-positive number, the function will accept it without any error or warning.

Afterwards, a draw action (like forward) will raise an exception. See below.

>>> 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"
>>>

My suggestion is pensize (and probably others) raises a TurtleGraphicsError if the width argument is less than 1.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

https://discuss.python.org/t/improving-the-turtle-library/61840/18

Linked PRs
  • gh-135268

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

turtle.py の pensize 実装から始め、文書化されている正の幅の要件の処理と、報告されている forward の失敗を比較してください。進める前にリンク先の議論と gh-135268 を確認してください。完了とは、無効な非正の幅が後の描画アクション中に失敗するのではなく、pensize の時点で処理されることを意味します。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
python
領域
computer-graphics
issue の種類
機能追加
難易度
3/5
見積もり時間
1〜2日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。