From a51d8355c3cbc597dde552f6dbeaadc43e0cdd8d Mon Sep 17 00:00:00 2001 From: liam-gersten Date: Thu, 27 Apr 2023 17:42:38 -0400 Subject: [PATCH 01/19] Working teleport method --- Lib/turtle.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Lib/turtle.py b/Lib/turtle.py index 1b369327bc8eff..c414059d571229 100644 --- a/Lib/turtle.py +++ b/Lib/turtle.py @@ -126,7 +126,7 @@ 'setworldcoordinates', 'textinput', 'title', 'tracer', 'turtles', 'update', 'window_height', 'window_width'] _tg_turtle_functions = ['back', 'backward', 'begin_fill', 'begin_poly', 'bk', - 'circle', 'clear', 'clearstamp', 'clearstamps', 'clone', 'color', + 'circle', 'clear', 'clearstamp', 'clearstamps', 'clone', 'color', 'teleport', 'degrees', 'distance', 'dot', 'down', 'end_fill', 'end_poly', 'fd', 'fillcolor', 'filling', 'forward', 'get_poly', 'getpen', 'getscreen', 'get_shapepoly', 'getturtle', 'goto', 'heading', 'hideturtle', 'home', 'ht', 'isdown', @@ -2710,6 +2710,23 @@ def _cc(self, args): if not ((0 <= r <= 255) and (0 <= g <= 255) and (0 <= b <= 255)): raise TurtleGraphicsError("bad color sequence: %s" % str(args)) return "#%02x%02x%02x" % (r, g, b) + + def teleport(self, x=None, y=None) -> None: + """ + Header + """ + pendown = self.isdown() + if pendown: + self.pen(pendown=False) + new_x, new_y = self._position + if x is not None and y is not None: + new_x, new_y = x, y + elif x is not None: + new_x, new_y = x, self._position[1] + elif y is not None: + new_x, new_y = self._position[0], y + self._position = Vec2D(new_x, new_y) + self.pen(pendown=pendown) def clone(self): """Create and return a clone of the turtle. From 7986926a0e0bbe7d907d12ec609a85b01c4d76a8 Mon Sep 17 00:00:00 2001 From: liam-gersten Date: Fri, 28 Apr 2023 12:09:07 -0400 Subject: [PATCH 02/19] Handle filling with teleport method --- Lib/turtle.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Lib/turtle.py b/Lib/turtle.py index c414059d571229..452669de833895 100644 --- a/Lib/turtle.py +++ b/Lib/turtle.py @@ -2711,13 +2711,16 @@ def _cc(self, args): raise TurtleGraphicsError("bad color sequence: %s" % str(args)) return "#%02x%02x%02x" % (r, g, b) - def teleport(self, x=None, y=None) -> None: + def teleport(self, x=None, y=None, fill_gap: bool = False) -> None: """ Header """ pendown = self.isdown() + was_filling = self.filling() if pendown: self.pen(pendown=False) + if was_filling and not fill_gap: + self.end_fill() new_x, new_y = self._position if x is not None and y is not None: new_x, new_y = x, y @@ -2726,7 +2729,9 @@ def teleport(self, x=None, y=None) -> None: elif y is not None: new_x, new_y = self._position[0], y self._position = Vec2D(new_x, new_y) - self.pen(pendown=pendown) + self.pen(pendown=pendown) + if was_filling and not fill_gap: + self.begin_fill() def clone(self): """Create and return a clone of the turtle. From 1054b3446bc550590a325208aacfbc281e406675 Mon Sep 17 00:00:00 2001 From: liam-gersten Date: Fri, 28 Apr 2023 12:26:31 -0400 Subject: [PATCH 03/19] Teleport method documentation --- Lib/turtle.py | 35 +++++++++++++++++++++++++++++++++-- 1 file changed, 33 insertions(+), 2 deletions(-) diff --git a/Lib/turtle.py b/Lib/turtle.py index 452669de833895..3d7dfe50c43dba 100644 --- a/Lib/turtle.py +++ b/Lib/turtle.py @@ -2712,8 +2712,39 @@ def _cc(self, args): return "#%02x%02x%02x" % (r, g, b) def teleport(self, x=None, y=None, fill_gap: bool = False) -> None: - """ - Header + """Instantly move turtle to an absolute position. + + Arguments: + x -- a number or None + y -- a number None + fill_gap -- a boolean None + + call: teleport(x, y) # two coordinates + --or: teleport(x) # teleport to x position, keeping y as is + --or: teleport(y=y) # teleport to y position, keeping x as is + --or: teleport(x, y, fill_gap=True) + # teleport but fill the gap in between + + Move turtle to an absolute position. Unlike goto(x, y), a line will not + be drawn. The turtle's orientation does not change. If currently + filling, the polygon(s) teleported from will be filled after leaving, + and filling will begin again after teleporting. This can be disabled + with fill_gap=True, which makes the imaginary line traveled during + teleporting act as a fill barrier like in goto(x, y). + + Example (for a Turtle instance named turtle): + >>> tp = turtle.pos() + >>> tp + (0.00, 0.00) + >>> turtle.teleport(60) + >>> turtle.pos() + (60.00,0.00) + >>> turtle.teleport(y=10) + >>> turtle.pos() + (60.00,10.00) + >>> turtle.teleport(20, 30) + >>> turtle.pos() + (20.00,30.00) """ pendown = self.isdown() was_filling = self.filling() From 5871c2c96971175b15bcc405e83abcbe336de78d Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Fri, 28 Apr 2023 18:04:23 +0000 Subject: [PATCH 04/19] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20b?= =?UTF-8?q?lurb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2023-04-28-18-04-23.gh-issue-88773.xXCNJw.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/Library/2023-04-28-18-04-23.gh-issue-88773.xXCNJw.rst diff --git a/Misc/NEWS.d/next/Library/2023-04-28-18-04-23.gh-issue-88773.xXCNJw.rst b/Misc/NEWS.d/next/Library/2023-04-28-18-04-23.gh-issue-88773.xXCNJw.rst new file mode 100644 index 00000000000000..942d70b948f06e --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-04-28-18-04-23.gh-issue-88773.xXCNJw.rst @@ -0,0 +1,2 @@ +Added func:`turtle.teleport` to turtle library. +Patch by Liam Gersten. From 494f47826e59325998eb315ac926107b0be9d252 Mon Sep 17 00:00:00 2001 From: liam-gersten Date: Fri, 28 Apr 2023 14:12:38 -0400 Subject: [PATCH 05/19] Fixed NEWS entry --- .../next/Library/2023-04-28-18-04-23.gh-issue-88773.xXCNJw.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2023-04-28-18-04-23.gh-issue-88773.xXCNJw.rst b/Misc/NEWS.d/next/Library/2023-04-28-18-04-23.gh-issue-88773.xXCNJw.rst index 942d70b948f06e..463bf70456b7ab 100644 --- a/Misc/NEWS.d/next/Library/2023-04-28-18-04-23.gh-issue-88773.xXCNJw.rst +++ b/Misc/NEWS.d/next/Library/2023-04-28-18-04-23.gh-issue-88773.xXCNJw.rst @@ -1,2 +1,2 @@ -Added func:`turtle.teleport` to turtle library. +Added :func:`turtle.teleport` to turtle library. Patch by Liam Gersten. From 2fd8edacb9342f63364677cd4e0c9812eb26d13b Mon Sep 17 00:00:00 2001 From: Terry Jan Reedy Date: Fri, 28 Apr 2023 15:15:02 -0400 Subject: [PATCH 06/19] Update Misc/NEWS.d/next/Library/2023-04-28-18-04-23.gh-issue-88773.xXCNJw.rst --- .../next/Library/2023-04-28-18-04-23.gh-issue-88773.xXCNJw.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Misc/NEWS.d/next/Library/2023-04-28-18-04-23.gh-issue-88773.xXCNJw.rst b/Misc/NEWS.d/next/Library/2023-04-28-18-04-23.gh-issue-88773.xXCNJw.rst index 463bf70456b7ab..48156915d52b19 100644 --- a/Misc/NEWS.d/next/Library/2023-04-28-18-04-23.gh-issue-88773.xXCNJw.rst +++ b/Misc/NEWS.d/next/Library/2023-04-28-18-04-23.gh-issue-88773.xXCNJw.rst @@ -1,2 +1 @@ -Added :func:`turtle.teleport` to turtle library. -Patch by Liam Gersten. +Added :func:`turtle.teleport` to turtle library to move a turtle to a new point without tracing a line, visible or invisible. Patch by Liam Gersten. From ba2920e0810020a6959291cc15c2e7d781673ec0 Mon Sep 17 00:00:00 2001 From: liam-gersten Date: Fri, 28 Apr 2023 15:22:18 -0400 Subject: [PATCH 07/19] Made new coord assignment more concise --- Lib/turtle.py | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/Lib/turtle.py b/Lib/turtle.py index 3d7dfe50c43dba..2160d91262968c 100644 --- a/Lib/turtle.py +++ b/Lib/turtle.py @@ -2752,13 +2752,8 @@ def teleport(self, x=None, y=None, fill_gap: bool = False) -> None: self.pen(pendown=False) if was_filling and not fill_gap: self.end_fill() - new_x, new_y = self._position - if x is not None and y is not None: - new_x, new_y = x, y - elif x is not None: - new_x, new_y = x, self._position[1] - elif y is not None: - new_x, new_y = self._position[0], y + new_x = x if x is not None else self._position[0] + new_y = y if y is not None else self._position[1] self._position = Vec2D(new_x, new_y) self.pen(pendown=pendown) if was_filling and not fill_gap: From f8a9681040272d9eea515752d19c0f3663686a5e Mon Sep 17 00:00:00 2001 From: liam-gersten Date: Fri, 28 Apr 2023 15:39:19 -0400 Subject: [PATCH 08/19] Teleport documentation in Doc/library/turtle.rst --- Doc/library/turtle.rst | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/Doc/library/turtle.rst b/Doc/library/turtle.rst index 05392d04e52263..bfdc3de9de0ff0 100644 --- a/Doc/library/turtle.rst +++ b/Doc/library/turtle.rst @@ -107,6 +107,7 @@ Turtle motion | :func:`right` | :func:`rt` | :func:`left` | :func:`lt` | :func:`goto` | :func:`setpos` | :func:`setposition` + | :func:`teleport` | :func:`setx` | :func:`sety` | :func:`setheading` | :func:`seth` @@ -372,6 +373,44 @@ Turtle motion (0.00,0.00) +.. function:: teleport(x, y=None) + + :param x: a number or ``None`` + :param y: a number or ``None`` + :param fill_gap: a boolean + + Move turtle to an absolute position. Unlike goto(x, y), a line will not + be drawn. The turtle's orientation does not change. If currently + filling, the polygon(s) teleported from will be filled after leaving, + and filling will begin again after teleporting. This can be disabled + with fill_gap=True, which makes the imaginary line traveled during + teleporting act as a fill barrier like in goto(x, y). + + .. doctest:: + :skipif: _tkinter is None + :hide: + + >>> turtle.goto(0, 0) + + .. doctest:: + :skipif: _tkinter is None + + >>> tp = turtle.pos() + >>> tp + (0.00, 0.00) + >>> turtle.teleport(60) + >>> turtle.pos() + (60.00,0.00) + >>> turtle.teleport(y=10) + >>> turtle.pos() + (60.00,10.00) + >>> turtle.teleport(20, 30) + >>> turtle.pos() + (20.00,30.00) + + .. versionadded: 3.12 + + .. function:: setx(x) :param x: a number (integer or float) From 7cec9b6592eeae70c9dff0cf585f5e6799951b6f Mon Sep 17 00:00:00 2001 From: Liam Gersten Date: Fri, 28 Apr 2023 16:10:35 -0400 Subject: [PATCH 09/19] Update Doc/library/turtle.rst Co-authored-by: Hugo van Kemenade --- Doc/library/turtle.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/turtle.rst b/Doc/library/turtle.rst index bfdc3de9de0ff0..99b84f584c7fa7 100644 --- a/Doc/library/turtle.rst +++ b/Doc/library/turtle.rst @@ -383,7 +383,7 @@ Turtle motion be drawn. The turtle's orientation does not change. If currently filling, the polygon(s) teleported from will be filled after leaving, and filling will begin again after teleporting. This can be disabled - with fill_gap=True, which makes the imaginary line traveled during + with fill_gap=True, which makes the imaginary line traveled during teleporting act as a fill barrier like in goto(x, y). .. doctest:: From eec5411e6ff9141b6f70e9cf76ac6f4fd15587af Mon Sep 17 00:00:00 2001 From: Liam Gersten Date: Fri, 28 Apr 2023 16:11:08 -0400 Subject: [PATCH 10/19] Update Misc/NEWS.d/next/Library/2023-04-28-18-04-23.gh-issue-88773.xXCNJw.rst Co-authored-by: Hugo van Kemenade --- .../next/Library/2023-04-28-18-04-23.gh-issue-88773.xXCNJw.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Library/2023-04-28-18-04-23.gh-issue-88773.xXCNJw.rst b/Misc/NEWS.d/next/Library/2023-04-28-18-04-23.gh-issue-88773.xXCNJw.rst index 48156915d52b19..f14c9533f3af87 100644 --- a/Misc/NEWS.d/next/Library/2023-04-28-18-04-23.gh-issue-88773.xXCNJw.rst +++ b/Misc/NEWS.d/next/Library/2023-04-28-18-04-23.gh-issue-88773.xXCNJw.rst @@ -1 +1 @@ -Added :func:`turtle.teleport` to turtle library to move a turtle to a new point without tracing a line, visible or invisible. Patch by Liam Gersten. +Added :func:`turtle.teleport` to the :mod:`turtle` module to move a turtle to a new point without tracing a line, visible or invisible. Patch by Liam Gersten. From ca3d9c5b48676c36459789ccafb50b9479191109 Mon Sep 17 00:00:00 2001 From: liam-gersten Date: Fri, 28 Apr 2023 16:35:56 -0400 Subject: [PATCH 11/19] Partial teleport method in TNavigator for testing in TestTNavigator --- Lib/turtle.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Lib/turtle.py b/Lib/turtle.py index 2160d91262968c..cce92c7e197b95 100644 --- a/Lib/turtle.py +++ b/Lib/turtle.py @@ -1614,6 +1614,13 @@ def _goto(self, end): """move turtle to position end.""" self._position = end + def teleport(self, x=None, y=None, fill_gap: bool = False) -> None: + """To be overwritten by child class RawTurtle. + Includes no TPen references.""" + new_x = x if x is not None else self._position[0] + new_y = y if y is not None else self._position[1] + self._position = Vec2D(new_x, new_y) + def forward(self, distance): """Move the turtle forward by the specified distance. From 02712b336899d4e3da0332dbf8a670896e9bbf8d Mon Sep 17 00:00:00 2001 From: liam-gersten Date: Fri, 28 Apr 2023 16:45:18 -0400 Subject: [PATCH 12/19] Partial teleport method in TPen for testing in TestTPen --- Lib/turtle.py | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/Lib/turtle.py b/Lib/turtle.py index cce92c7e197b95..684371fbee271d 100644 --- a/Lib/turtle.py +++ b/Lib/turtle.py @@ -2300,6 +2300,15 @@ def fillcolor(self, *args): else: return self._color(self._fillcolor) + def teleport(self, x=None, y=None, fill_gap: bool = False) -> None: + """To be overwritten by child class RawTurtle. + Includes no TNavigator references. + """ + pendown = self.isdown() + if pendown: + self.pen(pendown=False) + self.pen(pendown=pendown) + def showturtle(self): """Makes the turtle visible. From 8db9bf35567a091ce9696c805c9c18bfba9d3fce Mon Sep 17 00:00:00 2001 From: liam-gersten Date: Fri, 28 Apr 2023 16:46:09 -0400 Subject: [PATCH 13/19] Teleport tests in TestTNavigator and TestTPen --- Lib/test/test_turtle.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/Lib/test/test_turtle.py b/Lib/test/test_turtle.py index 95af84e3779824..1e11fe5f6c0422 100644 --- a/Lib/test/test_turtle.py +++ b/Lib/test/test_turtle.py @@ -267,6 +267,11 @@ def test_goto(self): self.assertAlmostEqual(self.nav.xcor(), 100) self.assertAlmostEqual(self.nav.ycor(), -100) + def test_teleport(self): + self.nav.teleport(20, -30) + self.assertAlmostEqual(self.nav.xcor(), 20) + self.assertAlmostEqual(self.nav.ycor(), -30) + def test_pos(self): self.assertEqual(self.nav.pos(), self.nav._position) self.nav.goto(100, -100) @@ -440,6 +445,17 @@ def test_showturtle_hideturtle_and_isvisible(self): tpen.showturtle() self.assertTrue(tpen.isvisible()) + def test_teleport(self): + + tpen = turtle.TPen() + + tpen.penup() + tpen.teleport(100, 100) + self.assertTrue(not tpen.isdown()) + tpen.pendown() + tpen.teleport(-100, -100) + self.assertTrue(tpen.isdown()) + if __name__ == '__main__': unittest.main() From ae01a3e02d52e52601e83b8da3fb2308134dc022 Mon Sep 17 00:00:00 2001 From: liam-gersten Date: Fri, 28 Apr 2023 16:50:50 -0400 Subject: [PATCH 14/19] Made teleport appear in alphabetical order --- Lib/turtle.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/turtle.py b/Lib/turtle.py index 684371fbee271d..1c857efe1d5649 100644 --- a/Lib/turtle.py +++ b/Lib/turtle.py @@ -126,7 +126,7 @@ 'setworldcoordinates', 'textinput', 'title', 'tracer', 'turtles', 'update', 'window_height', 'window_width'] _tg_turtle_functions = ['back', 'backward', 'begin_fill', 'begin_poly', 'bk', - 'circle', 'clear', 'clearstamp', 'clearstamps', 'clone', 'color', 'teleport', + 'circle', 'clear', 'clearstamp', 'clearstamps', 'clone', 'color', 'degrees', 'distance', 'dot', 'down', 'end_fill', 'end_poly', 'fd', 'fillcolor', 'filling', 'forward', 'get_poly', 'getpen', 'getscreen', 'get_shapepoly', 'getturtle', 'goto', 'heading', 'hideturtle', 'home', 'ht', 'isdown', @@ -135,7 +135,7 @@ 'pu', 'radians', 'right', 'reset', 'resizemode', 'rt', 'seth', 'setheading', 'setpos', 'setposition', 'settiltangle', 'setundobuffer', 'setx', 'sety', 'shape', 'shapesize', 'shapetransform', 'shearfactor', 'showturtle', - 'speed', 'st', 'stamp', 'tilt', 'tiltangle', 'towards', + 'speed', 'st', 'stamp', 'teleport', 'tilt', 'tiltangle', 'towards', 'turtlesize', 'undo', 'undobufferentries', 'up', 'width', 'write', 'xcor', 'ycor'] _tg_utilities = ['write_docstringdict', 'done'] From 07ae3da2ee5e1cc6c9cf29ec03947f1b54a212ae Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Fri, 28 Apr 2023 17:45:59 -0700 Subject: [PATCH 15/19] Attempt to fix the doctests. stamp ids are global an incrementing, do not expose them as doctest constants. --- Doc/library/turtle.rst | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/Doc/library/turtle.rst b/Doc/library/turtle.rst index 99b84f584c7fa7..fcf4e35a2465eb 100644 --- a/Doc/library/turtle.rst +++ b/Doc/library/turtle.rst @@ -397,7 +397,7 @@ Turtle motion >>> tp = turtle.pos() >>> tp - (0.00, 0.00) + (0.00,0.00) >>> turtle.teleport(60) >>> turtle.pos() (60.00,0.00) @@ -576,8 +576,7 @@ Turtle motion :skipif: _tkinter is None >>> turtle.color("blue") - >>> turtle.stamp() - 11 + >>> stamp_id = turtle.stamp() >>> turtle.fd(50) @@ -614,15 +613,8 @@ Turtle motion .. doctest:: >>> for i in range(8): - ... turtle.stamp(); turtle.fd(30) - 13 - 14 - 15 - 16 - 17 - 18 - 19 - 20 + ... unused_stamp_id = turtle.stamp() + ... turtle.fd(30) >>> turtle.clearstamps(2) >>> turtle.clearstamps(-2) >>> turtle.clearstamps() From d648f52b288a3e284216c72e4e1aebec99cebc56 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Fri, 28 Apr 2023 17:58:18 -0700 Subject: [PATCH 16/19] Mention fill_gap in the teleport prototype. --- Doc/library/turtle.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/turtle.rst b/Doc/library/turtle.rst index fcf4e35a2465eb..56c78a1533bf7a 100644 --- a/Doc/library/turtle.rst +++ b/Doc/library/turtle.rst @@ -373,7 +373,7 @@ Turtle motion (0.00,0.00) -.. function:: teleport(x, y=None) +.. function:: teleport(x, y=None, fill_gap=False) :param x: a number or ``None`` :param y: a number or ``None`` From 2baaf85255cf1a85b93935e8807c3cfe6437fb64 Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Fri, 28 Apr 2023 18:03:05 -0700 Subject: [PATCH 17/19] Make fill_gap a keyword only argument. --- Lib/turtle.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Lib/turtle.py b/Lib/turtle.py index 1c857efe1d5649..2de406e0f517af 100644 --- a/Lib/turtle.py +++ b/Lib/turtle.py @@ -1614,7 +1614,7 @@ def _goto(self, end): """move turtle to position end.""" self._position = end - def teleport(self, x=None, y=None, fill_gap: bool = False) -> None: + def teleport(self, x=None, y=None, *, fill_gap: bool = False) -> None: """To be overwritten by child class RawTurtle. Includes no TPen references.""" new_x = x if x is not None else self._position[0] @@ -2300,7 +2300,7 @@ def fillcolor(self, *args): else: return self._color(self._fillcolor) - def teleport(self, x=None, y=None, fill_gap: bool = False) -> None: + def teleport(self, x=None, y=None, *, fill_gap: bool = False) -> None: """To be overwritten by child class RawTurtle. Includes no TNavigator references. """ @@ -2727,13 +2727,13 @@ def _cc(self, args): raise TurtleGraphicsError("bad color sequence: %s" % str(args)) return "#%02x%02x%02x" % (r, g, b) - def teleport(self, x=None, y=None, fill_gap: bool = False) -> None: + def teleport(self, x=None, y=None, *, fill_gap: bool = False) -> None: """Instantly move turtle to an absolute position. Arguments: x -- a number or None y -- a number None - fill_gap -- a boolean None + fill_gap -- a boolean This argument must be specified by name. call: teleport(x, y) # two coordinates --or: teleport(x) # teleport to x position, keeping y as is @@ -2751,7 +2751,7 @@ def teleport(self, x=None, y=None, fill_gap: bool = False) -> None: Example (for a Turtle instance named turtle): >>> tp = turtle.pos() >>> tp - (0.00, 0.00) + (0.00,0.00) >>> turtle.teleport(60) >>> turtle.pos() (60.00,0.00) From 203a0f3c9a3dfad6a15a89af13c1165eaca823aa Mon Sep 17 00:00:00 2001 From: "Gregory P. Smith" Date: Fri, 28 Apr 2023 18:05:27 -0700 Subject: [PATCH 18/19] Align docs with fill_gap being keyword only. --- Doc/library/turtle.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/turtle.rst b/Doc/library/turtle.rst index 56c78a1533bf7a..10138f4f406f85 100644 --- a/Doc/library/turtle.rst +++ b/Doc/library/turtle.rst @@ -373,7 +373,7 @@ Turtle motion (0.00,0.00) -.. function:: teleport(x, y=None, fill_gap=False) +.. function:: teleport(x, y=None, *, fill_gap=False) :param x: a number or ``None`` :param y: a number or ``None`` From dac054e89636e0773590ab93e9d8e5954e90ce53 Mon Sep 17 00:00:00 2001 From: liam-gersten Date: Sun, 30 Apr 2023 12:53:30 -0400 Subject: [PATCH 19/19] Testing changes for fill_gap arg and assertFalse --- Lib/test/test_turtle.py | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/Lib/test/test_turtle.py b/Lib/test/test_turtle.py index 1e11fe5f6c0422..3f9f129a3dd200 100644 --- a/Lib/test/test_turtle.py +++ b/Lib/test/test_turtle.py @@ -268,9 +268,12 @@ def test_goto(self): self.assertAlmostEqual(self.nav.ycor(), -100) def test_teleport(self): - self.nav.teleport(20, -30) + self.nav.teleport(20, -30, fill_gap=True) self.assertAlmostEqual(self.nav.xcor(), 20) self.assertAlmostEqual(self.nav.ycor(), -30) + self.nav.teleport(-20, 30, fill_gap=False) + self.assertAlmostEqual(self.nav.xcor(), -20) + self.assertAlmostEqual(self.nav.ycor(), 30) def test_pos(self): self.assertEqual(self.nav.pos(), self.nav._position) @@ -449,12 +452,13 @@ def test_teleport(self): tpen = turtle.TPen() - tpen.penup() - tpen.teleport(100, 100) - self.assertTrue(not tpen.isdown()) - tpen.pendown() - tpen.teleport(-100, -100) - self.assertTrue(tpen.isdown()) + for fill_gap_value in [True, False]: + tpen.penup() + tpen.teleport(100, 100, fill_gap=fill_gap_value) + self.assertFalse(tpen.isdown()) + tpen.pendown() + tpen.teleport(-100, -100, fill_gap=fill_gap_value) + self.assertTrue(tpen.isdown()) if __name__ == '__main__':