cpython: 1628484c9408 (original) (raw)
--- a/Lib/turtle.py +++ b/Lib/turtle.py @@ -1288,7 +1288,7 @@ class TurtleScreen(TurtleScreenBase): def _incrementudc(self): """Increment update counter.""" if not TurtleScreen._RUNNING:
TurtleScreen._RUNNNING = True[](#l1.7)
TurtleScreen._RUNNING = True[](#l1.8) raise Terminator[](#l1.9) if self._tracing > 0:[](#l1.10) self._updatecounter += 1[](#l1.11)
@@ -3754,7 +3754,7 @@ class _Screen(TurtleScreen): Turtle._screen = None _Screen._root = None _Screen._canvas = None
TurtleScreen._RUNNING = True[](#l1.16)
TurtleScreen._RUNNING = False[](#l1.17) root.destroy()[](#l1.18)
def bye(self): @@ -3795,7 +3795,6 @@ class _Screen(TurtleScreen): except AttributeError: exit(0) - class Turtle(RawTurtle): """RawTurtle auto-creating (scrolled) canvas. @@ -3818,18 +3817,6 @@ class Turtle(RawTurtle): Pen = Turtle -def _getpen():
- """Create the 'anonymous' turtle if not already present."""
- if Turtle._pen is None:
Turtle._pen = Turtle()[](#l1.36)
- return Turtle._pen
- """Create a TurtleScreen if not already present."""
- if Turtle._screen is None:
Turtle._screen = Screen()[](#l1.42)
- return Turtle._screen
- def write_docstringdict(filename="turtle_docstringdict"): """Create and write docstring-dictionary to file. @@ -3952,26 +3939,38 @@ def _screen_docrevise(docstr):
as functions. So we can enhance, change, add, delete methods to these
classes and do not need to change anything here.
- -for methodname in _tg_screen_functions:
- pl1, pl2 = getmethparlist(eval('_Screen.' + methodname))
- if pl1 == "":
print(">>>>>>", pl1, pl2)[](#l1.56)
continue[](#l1.57)
- defstr = ("def %(key)s%(pl1)s: return _getscreen().%(key)s%(pl2)s" %
{'key':methodname, 'pl1':pl1, 'pl2':pl2})[](#l1.59)
- exec(defstr)
- eval(methodname).doc = _screen_docrevise(eval('_Screen.'+methodname).doc)
- -for methodname in _tg_turtle_functions:
- pl1, pl2 = getmethparlist(eval('Turtle.' + methodname))
- if pl1 == "":
print(">>>>>>", pl1, pl2)[](#l1.66)
continue[](#l1.67)
- defstr = ("def %(key)s%(pl1)s: return _getpen().%(key)s%(pl2)s" %
{'key':methodname, 'pl1':pl1, 'pl2':pl2})[](#l1.69)
- exec(defstr)
- eval(methodname).doc = _turtle_docrevise(eval('Turtle.'+methodname).doc)
+__func_body = """[](#l1.72) +def {name}{paramslist}:
- if {obj} is None:
if not TurtleScreen._RUNNING:[](#l1.75)
TurtleScreen._RUNNING = True[](#l1.76)
raise Terminator[](#l1.77)
{obj} = {init}[](#l1.78)
- try:
return {obj}.{name}{argslist}[](#l1.80)
- except TK.TclError:
if not TurtleScreen._RUNNING:[](#l1.82)
TurtleScreen._RUNNING = True[](#l1.83)
raise Terminator[](#l1.84)
raise[](#l1.85)
+""" + +def _make_global_funcs(functions, cls, obj, init, docrevise):
- for methodname in functions:
method = getattr(cls, methodname)[](#l1.90)
pl1, pl2 = getmethparlist(method)[](#l1.91)
if pl1 == "":[](#l1.92)
print(">>>>>>", pl1, pl2)[](#l1.93)
continue[](#l1.94)
defstr = __func_body.format(obj=obj, init=init, name=methodname,[](#l1.95)
paramslist=pl1, argslist=pl2)[](#l1.96)
exec(defstr, globals())[](#l1.97)
globals()[methodname].__doc__ = docrevise(method.__doc__)[](#l1.98)
+ +_make_global_funcs(_tg_screen_functions, _Screen,
'Turtle._screen', 'Screen()', _screen_docrevise)[](#l1.101)
+_make_global_funcs(_tg_turtle_functions, Turtle,
'Turtle._pen', 'Turtle()', _turtle_docrevise)[](#l1.103)
--- a/Lib/turtledemo/main.py +++ b/Lib/turtledemo/main.py @@ -344,6 +344,8 @@ class DemoWindow(object): else: self.state = DONE except turtle.Terminator:
if self.root is None:[](#l2.7)
return[](#l2.8) self.state = DONE[](#l2.9) result = "stopped!"[](#l2.10) if self.state == DONE:[](#l2.11)
@@ -369,7 +371,9 @@ class DemoWindow(object): turtle.TurtleScreen._RUNNING = False def _destroy(self):
turtle.TurtleScreen._RUNNING = False[](#l2.16) self.root.destroy()[](#l2.17)
self.root = None[](#l2.18)
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -13,6 +13,9 @@ Core and Builtins Library ------- +- Issue #6639: Module-level turtle functions no longer raise TclError after