Skip to content

Commit dae41e0

Browse files
author
marat
committed
gh-138845: Correct turtle module documentation misconceptions
1 parent 7168e98 commit dae41e0

File tree

2 files changed

+122
-25
lines changed

2 files changed

+122
-25
lines changed

Doc/library/turtle.rst

Lines changed: 68 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -524,9 +524,17 @@ Turtle motion
524524

525525
:param angle: a number (integer or float)
526526

527-
Turn turtle right by *angle* units. (Units are by default degrees, but
528-
can be set via the :func:`degrees` and :func:`radians` functions.) Angle
529-
orientation depends on the turtle mode, see :func:`mode`.
527+
Turn turtle right by *angle* units.
528+
529+
The unit of measurement is controlled by :func:`degrees` and
530+
:func:`radians`:
531+
532+
* By default, 360.0 units form a full circle (degrees).
533+
* After calling :func:`radians`, ``2*math.pi`` units form a full circle.
534+
* Custom values can be set with :func:`degrees(fullcircle)`.
535+
536+
Orientation of the turn depends in the current turtle mode,
537+
see :func:`mode`.
530538

531539
.. doctest::
532540
:skipif: _tkinter is None
@@ -549,9 +557,17 @@ Turtle motion
549557

550558
:param angle: a number (integer or float)
551559

552-
Turn turtle left by *angle* units. (Units are by default degrees, but
553-
can be set via the :func:`degrees` and :func:`radians` functions.) Angle
554-
orientation depends on the turtle mode, see :func:`mode`.
560+
Turn turtle left by *angle* units.
561+
562+
The unit of measurement is controlled by :func:`degrees` and
563+
:func:`radians`:
564+
565+
* By default, 360.0 units form a full circle (degrees).
566+
* After calling :func:`radians`, ``2*math.pi`` units form a full circle.
567+
* Custom values can be set with :func:`degrees(fullcircle)`.
568+
569+
Orientation of the turn depends in the current turtle mode,
570+
see :func:`mode`.
555571

556572
.. doctest::
557573
:skipif: _tkinter is None
@@ -1008,10 +1024,16 @@ Settings for measurement
10081024

10091025
.. function:: degrees(fullcircle=360.0)
10101026

1011-
:param fullcircle: a number
1027+
:param fullcircle: a number representing units for a full circle
10121028

1013-
Set angle measurement units, i.e. set number of "degrees" for a full circle.
1014-
Default value is 360 degrees.
1029+
Set angle measurement units so that a full circle is *fullcircle*
1030+
units. The default value is ``360.0`` (i.e. conventional degrees).
1031+
1032+
.. seealso::
1033+
:func:`radians`
1034+
:func:`mode`
1035+
:func:`left`
1036+
:func:`right`
10151037

10161038
.. doctest::
10171039
:skipif: _tkinter is None
@@ -1030,11 +1052,25 @@ Settings for measurement
10301052
>>> turtle.heading()
10311053
90.0
10321054

1055+
>>> # Change angle measurement unit to radians (where a full circle
1056+
>>> # equals 2π radians, so 90 degrees becomes π/2 radians)
1057+
>>> turtle.degrees(2*math.pi)
1058+
>>> turtle.heading()
1059+
1.5707963267948966
1060+
10331061

10341062
.. function:: radians()
10351063

1036-
Set the angle measurement units to radians. Equivalent to
1037-
``degrees(2*math.pi)``.
1064+
Set the angle measurement unit to radians.
1065+
1066+
Equivalent to::
1067+
1068+
degrees(2*math.pi)
1069+
1070+
After this call, one full circle correspond to
1071+
``2*math.pi`` units.
1072+
1073+
.. seealso:: :func:`degrees`, :func:`left`, :func:`right`
10381074

10391075
.. doctest::
10401076
:skipif: _tkinter is None
@@ -1356,8 +1392,27 @@ More drawing control
13561392

13571393
.. function:: reset()
13581394

1359-
Delete the turtle's drawings from the screen, re-center the turtle and set
1360-
variables to the default values.
1395+
Delete the turtle's drawings from the screen. Move the turtle
1396+
to position ``(0, 0)``, set its heading to the default
1397+
(facing east in standard mode) and restore the following state
1398+
variables to their initial values:
1399+
1400+
* position: ``(0, 0)``
1401+
* heading: ``0`` (east)
1402+
* pen state: down (drawing)
1403+
* pensize: ``1``
1404+
* pencolor: black
1405+
* fillcolor: white
1406+
* speed: ``3``
1407+
* turtle visibility: shown
1408+
* shape size: ``(1.0, 1.0)`` (no stretch)
1409+
* shape shear: ``0.0`` (no shear)
1410+
* shape tilt: ``0.0`` (no tilt)
1411+
1412+
.. note::
1413+
The angle unit is **not reset** to degrees. If
1414+
:func:`radians` was used before :func:`reset`,
1415+
the unit remains radians.
13611416

13621417
.. doctest::
13631418
:skipif: _tkinter is None

Lib/turtle.py

Lines changed: 54 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,7 +1580,7 @@ def reset(self):
15801580
Will be overwritten by parent class
15811581
"""
15821582
self._position = Vec2D(0.0, 0.0)
1583-
self._orient = TNavigator.START_ORIENTATION[self._mode]
1583+
self._orient = TNavigator.START_ORIENTATION[self._mode]
15841584

15851585
def _setmode(self, mode=None):
15861586
"""Set turtle-mode to 'standard', 'world' or 'logo'.
@@ -1612,9 +1612,8 @@ def degrees(self, fullcircle=360.0):
16121612
Optional argument:
16131613
fullcircle - a number
16141614
1615-
Set angle measurement units, i. e. set number
1616-
of 'degrees' for a full circle. Default value is
1617-
360 degrees.
1615+
Set angle measurement units so that a full circle is *fullcircle*
1616+
units. The default value is `360.0` (i.e. conventional degrees).
16181617
16191618
Example (for a Turtle instance named turtle):
16201619
>>> turtle.left(90)
@@ -1627,12 +1626,20 @@ def degrees(self, fullcircle=360.0):
16271626
>>> turtle.heading()
16281627
100
16291628
1629+
Change angle measurement unit to radians (where a full circle
1630+
equals 2π radians, so 90 degrees becomes π/2 radians)
1631+
>>> turtle.degrees(2*math.pi)
1632+
>>> turtle.heading()
1633+
1.5707963267948966
1634+
16301635
"""
16311636
self._setDegreesPerAU(fullcircle)
16321637

16331638
def radians(self):
16341639
""" Set the angle measurement units to radians.
16351640
1641+
Equivalent to calling `degrees(2*math.pi)`
1642+
16361643
No arguments.
16371644
16381645
Example (for a Turtle instance named turtle):
@@ -1716,9 +1723,17 @@ def right(self, angle):
17161723
Argument:
17171724
angle -- a number (integer or float)
17181725
1719-
Turn turtle right by angle units. (Units are by default degrees,
1720-
but can be set via the degrees() and radians() functions.)
1721-
Angle orientation depends on mode. (See this.)
1726+
Turn turtle right by *angle* units.
1727+
1728+
The unit of measurement is controlled by `degrees()` and
1729+
`radians()`:
1730+
1731+
* By default, 360.0 units form a full circle (degrees).
1732+
* After calling `radians()`, ``2*math.pi`` units form a full circle.
1733+
* Custom values can be set with `degrees(fullcircle)`.
1734+
1735+
Orientation of the turn depends in the current turtle mode,
1736+
see function `mode()`.
17221737
17231738
Example (for a Turtle instance named turtle):
17241739
>>> turtle.heading()
@@ -1737,9 +1752,17 @@ def left(self, angle):
17371752
Argument:
17381753
angle -- a number (integer or float)
17391754
1740-
Turn turtle left by angle units. (Units are by default degrees,
1741-
but can be set via the degrees() and radians() functions.)
1742-
Angle orientation depends on mode. (See this.)
1755+
Turn turtle left by *angle* units.
1756+
1757+
The unit of measurement is controlled by `degrees()` and
1758+
`radians()`:
1759+
1760+
* By default, 360.0 units form a full circle (degrees).
1761+
* After calling `radians()`, ``2*math.pi`` units form a full circle.
1762+
* Custom values can be set with `degrees(fullcircle)`.
1763+
1764+
Orientation of the turn depends in the current turtle mode,
1765+
see function `mode()`.
17431766
17441767
Example (for a Turtle instance named turtle):
17451768
>>> turtle.heading()
@@ -2622,8 +2645,27 @@ def reset(self):
26222645
26232646
No argument.
26242647
2625-
Delete the turtle's drawings from the screen, re-center the turtle
2626-
and set variables to the default values.
2648+
Delete the turtle's drawings from the screen. Move the turtle
2649+
to position `(0, 0)`, set its heading to the default
2650+
(facing east in standard mode) and restore the following state
2651+
variables to their initial values:
2652+
2653+
- position: `(0, 0)`
2654+
- heading: `0` (east)
2655+
- pen state: down (drawing)
2656+
- pensize: `1`
2657+
- pencolor: black
2658+
- fillcolor: white
2659+
- speed: `3`
2660+
- turtle visibility: shown
2661+
- shape size: `(1.0, 1.0)` (no stretch)
2662+
- shape shear: `0.0` (no shear)
2663+
- shape tilt: `0.0` (no tilt)
2664+
2665+
Note:
2666+
The angle unit is **not reset** to degrees. If
2667+
`radians()` was used before `reset()`,
2668+
the unit remains radians.
26272669
26282670
Example (for a Turtle instance named turtle):
26292671
>>> turtle.position()

0 commit comments

Comments
 (0)