Skip to content

Commit 28a5ac6

Browse files
committed
Address review comments
1 parent 5ee489b commit 28a5ac6

File tree

4 files changed

+23
-17
lines changed

4 files changed

+23
-17
lines changed

Doc/library/turtle.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,18 +222,18 @@ If you have Python 3.14 or later, you don't need to call :func:`begin_fill` and
222222
example::
223223

224224
with fill():
225-
for i in range(4):
226-
forward(100)
227-
right(90)
225+
for i in range(4):
226+
forward(100)
227+
right(90)
228228

229229
forward(200)
230230

231231
The code above is equivalent to::
232232

233233
begin_fill()
234234
for i in range(4):
235-
forward(100)
236-
right(90)
235+
forward(100)
236+
right(90)
237237
end_fill()
238238

239239
forward(200)
@@ -377,6 +377,7 @@ Pen control
377377
378378
Filling
379379
| :func:`filling`
380+
| :func:`fill`
380381
| :func:`begin_fill`
381382
| :func:`end_fill`
382383

Doc/whatsnew/3.14.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -438,6 +438,15 @@ sys
438438
which only exists in specialized builds of Python, may now return objects
439439
from other interpreters than the one it's called in.
440440

441+
turtle
442+
------
443+
444+
* Add context managers for :func:`turtle.fill`, :func:`turtle.poly` and
445+
:func:`turtle.no_animation` for
446+
:func:`turtle.begin_fill`/:func:`turtle.end_fill`,
447+
:func:`turtle.begin_poly`/:func:`turtle.end_poly`, and
448+
:func:`turtle.tracer(0)`/:func:`turtle.tracer(1)`, respectively.
449+
(Contributed by Marie Roald and Yngve Mardal Moe in :gh:`126350`.)
441450

442451
unicodedata
443452
-----------

Lib/test/test_turtle.py

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
import re
44
import unittest
55
import unittest.mock
6-
import tempfile
76
import sys
7+
import tempfile
88
from contextlib import contextmanager
99
from test import support
1010
from test.support import import_helper
@@ -572,7 +572,6 @@ def test_no_animation_calls_update_at_exit(self):
572572

573573
class TestTurtle(unittest.TestCase):
574574
def test_begin_end_fill(self):
575-
"""begin_fill and end_fill counter each other."""
576575
with patch_screen():
577576
t = turtle.Turtle()
578577

@@ -583,7 +582,7 @@ def test_begin_end_fill(self):
583582
self.assertFalse(t.filling())
584583

585584
def test_fill(self):
586-
"""The context manager behaves like begin_ and end_ fill."""
585+
# The context manager behaves like begin_fill and end_fill.
587586
with patch_screen():
588587
t = turtle.Turtle()
589588

@@ -593,7 +592,7 @@ def test_fill(self):
593592
self.assertFalse(t.filling())
594593

595594
def test_fill_resets_after_exception(self):
596-
"""The context manager cleans up correctly after exceptions."""
595+
# The context manager cleans up correctly after exceptions.
597596
with patch_screen():
598597
t = turtle.Turtle()
599598
try:
@@ -604,7 +603,7 @@ def test_fill_resets_after_exception(self):
604603
self.assertFalse(t.filling())
605604

606605
def test_fill_context_when_filling(self):
607-
"""The context manager works even when the turtle is already filling."""
606+
# The context manager works even when the turtle is already filling.
608607
with patch_screen():
609608
t = turtle.Turtle()
610609

@@ -615,7 +614,6 @@ def test_fill_context_when_filling(self):
615614
self.assertFalse(t.filling())
616615

617616
def test_begin_end_poly(self):
618-
"""begin_fill and end_poly counter each other."""
619617
with patch_screen():
620618
t = turtle.Turtle()
621619

@@ -626,7 +624,7 @@ def test_begin_end_poly(self):
626624
self.assertFalse(t._creatingPoly)
627625

628626
def test_poly(self):
629-
"""The context manager behaves like begin_ and end_ poly."""
627+
# The context manager behaves like begin_poly and end_poly.
630628
with patch_screen():
631629
t = turtle.Turtle()
632630

@@ -636,7 +634,7 @@ def test_poly(self):
636634
self.assertFalse(t._creatingPoly)
637635

638636
def test_poly_resets_after_exception(self):
639-
"""The context manager cleans up correctly after exceptions."""
637+
# The context manager cleans up correctly after exceptions.
640638
with patch_screen():
641639
t = turtle.Turtle()
642640
try:
@@ -647,8 +645,7 @@ def test_poly_resets_after_exception(self):
647645
self.assertFalse(t._creatingPoly)
648646

649647
def test_poly_context_when_creating_poly(self):
650-
"""The context manager works when the turtle is already creating poly.
651-
"""
648+
# The context manager works when the turtle is already creating poly.
652649
with patch_screen():
653650
t = turtle.Turtle()
654651

Lib/turtle.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,11 +107,10 @@
107107

108108
from os.path import isfile, split, join
109109
from pathlib import Path
110+
from contextlib import contextmanager
110111
from copy import deepcopy
111112
from tkinter import simpledialog
112113

113-
from contextlib import contextmanager
114-
115114
_tg_classes = ['ScrolledCanvas', 'TurtleScreen', 'Screen',
116115
'RawTurtle', 'Turtle', 'RawPen', 'Pen', 'Shape', 'Vec2D']
117116
_tg_screen_functions = ['addshape', 'bgcolor', 'bgpic', 'bye',

0 commit comments

Comments
 (0)