8000 Merge branch 'main' into iter_freelists · python/cpython@05f479c · GitHub
[go: up one dir, main page]

Skip to content

Commit 05f479c

Browse files
authored
Merge branch 'main' into iter_freelists
2 parents e296fbb + e1baa77 commit 05f479c

File tree

6 files changed

+40
-31
lines changed

6 files changed

+40
-31
lines changed

Doc/library/decimal.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,7 +1033,7 @@ New contexts can also be created using the :class:`Context` constructor
10331033
described below. In addition, the module provides three pre-made contexts:
10341034

10351035

1036-
.. class:: BasicContext
1036+
.. data:: BasicContext
10371037

10381038
This is a standard context defined by the General Decimal Arithmetic
10391039
Specification. Precision is set to nine. Rounding is set to
@@ -1044,7 +1044,7 @@ described below. In addition, the module provides three pre-made contexts:
10441044
Because many of the traps are enabled, this context is useful for debugging.
10451045

10461046

1047-
.. class:: ExtendedContext
1047+
.. data:: ExtendedContext
10481048

10491049
This is a standard context defined by the General Decimal Arithmetic
10501050
Specification. Precision is set to nine. Rounding is set to
@@ -1057,7 +1057,7 @@ described below. In addition, the module provides three pre-made contexts:
10571057
presence of conditions that would otherwise halt the program.
10581058

10591059

1060-
.. class:: DefaultContext
1060+
.. data:: DefaultContext
10611061

10621062
This context is used by the :class:`Context` constructor as a prototype for new
10631063
contexts. Changing a field (such a precision) has the effect of changing the

Doc/library/turtle.rst

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1823,7 +1823,8 @@ Window control
18231823

18241824
.. function:: bgpic(picname=None)
18251825

1826-
:param picname: a string, name of a gif-file or ``"nopic"``, or ``None``
1826+
:param picname: a string, name of an image file (PNG, GIF, PGM, and PPM)
1827+
or ``"nopic"``, or ``None``
8000
18271828

18281829
Set background image or return name of current backgroundimage. If *picname*
18291830
is a filename, set the corresponding image as background. If *picname* is
@@ -2200,9 +2201,9 @@ Settings and special methods
22002201
.. function:: register_shape(name, shape=None)
22012202
addshape(name, shape=None)
22022203

2203-
There are three different ways to call this function:
2204+
There are four different ways to call this function:
22042205

2205-
(1) *name* is the name of a gif-file and *shape* is ``None``: Install the
2206+
(1) *name* is the name of an image file (PNG, GIF, PGM, and PPM) and *shape* is ``None``: Install the
22062207
corresponding image shape. ::
22072208

22082209
>>> screen.register_shape("turtle.gif")
@@ -2211,20 +2212,33 @@ Settings and special methods
22112212
Image shapes *do not* rotate when turning the turtle, so they do not
22122213
display the heading of the turtle!
22132214

2214-
(2) *name* is an arbitrary string and *shape* is a tuple of pairs of
2215+
(2) *name* is an arbitrary string and *shape* is the name of an image file (PNG, GIF, PGM, and PPM): Install the
2216+
corresponding image shape. ::
2217+
2218+
>>> screen.register_shape("turtle", "turtle.gif")
2219+
2220+
.. note::
2221+
Image shapes *do not* rotate when turning the turtle, so they do not
2222+
display the heading of the turtle!
2223+
2224+
(3) *name* is an arbitrary string and *shape* is a tuple of pairs of
22152225
coordinates: Install the corresponding polygon shape.
22162226

22172227
.. doctest::
22182228
:skipif: _tkinter is None
22192229

22202230
>>> screen.register_shape("triangle", ((5,-3), (0,5), (-5,-3)))
22212231

2222-
(3) *name* is an arbitrary string and *shape* is a (compound) :class:`Shape`
2232+
(4) *name* is an arbitrary string and *shape* is a (compound) :class:`Shape`
22232233
object: Install the corresponding compound shape.
22242234

22252235
Add a turtle shape to TurtleScreen's shapelist. Only thusly registered
22262236
shapes can be used by issuing the command ``shape(shapename)``.
22272237

2238+
.. versionchanged:: next
2239+
Added support for PNG, PGM, and PPM image formats.
2240+
Both a shape name and an image file name can be specified.
2241+
22282242

22292243
.. function:: turtles()
22302244

Doc/whatsnew/3.3.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,8 +1147,8 @@ API changes
11471147
| :const:`MIN_EMIN` | ``-425000000`` | ``-999999999999999999`` |
11481148
+-------------------+----------------+-------------------------+
11491149

1150-
* In the context templates (:class:`~decimal.DefaultContext`,
1151-
:class:`~decimal.BasicContext` and :class:`~decimal.ExtendedContext`)
1150+
* In the context templates (:const:`~decimal.DefaultContext`,
1151+
:const:`~decimal.BasicContext` and :const:`~decimal.ExtendedContext`)
11521152
the magnitude of :attr:`~decimal.Context.Emax` and
11531153
:attr:`~decimal.Context.Emin` has changed to ``999999``.
11541154

Lib/turtle.py

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
turtle. So the turtles can more easily be used as a visual feedback
5252
instrument by the (beginning) programmer.
5353
54-
- Different turtle shapes, gif-images as turtle shapes, user defined
54+
- Different turtle shapes, image files as turtle shapes, user defined
5555
and user controllable turtle shapes, among them compound
5656
(multicolored) shapes. Turtle shapes can be stretched and tilted, which
5757
makes turtles very versatile geometrical objects.
@@ -468,7 +468,7 @@ def _blankimage(self):
468468

469469
def _image(self, filename):
470470
"""return an image object containing the
471-
imagedata from a gif-file named filename.
471+
imagedata from an image file named filename.
472472
"""
473473
return TK.PhotoImage(file=filename, master=self.cv)
474474

@@ -872,10 +872,7 @@ def __init__(self, type_, data=None):
872872
if isinstance(data, list):
873873
data = tuple(data)
874874
elif type_ == "image":
875-
if isinstance(data, str):
876-
if data.lower().endswith(".gif") and isfile(data):
877-
data = TurtleScreen._image(data)
878-
# else data assumed to be PhotoImage
875+
assert(isinstance(data, TK.PhotoImage))
879876
elif type_ == "compound":
880877
data = []
881878
else:
@@ -1100,14 +1097,18 @@ def register_shape(self, name, shape=None):
11001097
"""Adds a turtle shape to TurtleScreen's shapelist.
11011098
11021099
Arguments:
1103-
(1) name is the name of a gif-file and shape is None.
1100+
(1) name is the name of an image file (PNG, GIF, PGM, and PPM) and shape is None.
11041101
Installs the corresponding image shape.
11051102
!! Image-shapes DO NOT rotate when turning the turtle,
11061103
!! so they do not display the heading of the turtle!
1107-
(2) name is an arbitrary string and shape is a tuple
1104+
(2) name is an arbitrary string and shape is the name of an image file (PNG, GIF, PGM, and PPM).
1105+
Installs the corresponding image shape.
1106+
!! Image-shapes DO NOT rotate when turning the turtle,
1107+
!! so they do not display the heading of the turtle!
1108+
(3) name is an arbitrary string and shape is a tuple
11081109
of pairs of coordinates. Installs the corresponding
11091110
polygon shape
1110-
(3) name is an arbitrary string and shape is a
1111+
(4) name is an arbitrary string and shape is a
11111112
(compound) Shape object. Installs the corresponding
11121113
compound shape.
11131114
To use a shape, you have to issue the command shape(shapename).
@@ -1120,12 +1121,9 @@ def register_shape(self, name, shape=None):
11201121
11211122
"""
11221123
if shape is None:
1123-
# image
1124-
if name.lower().endswith(".gif"):
1125-
shape = Shape("image", self._image(name))
1126-
else:
1127-
raise TurtleGraphicsError("Bad arguments for register_shape.\n"
1128-
+ "Use help(register_shape)" )
1124+
shape = Shape("image", self._image(name))
1125+
elif isinstance(shape, str):
1126+
shape = Shape("image", self._image(shape))
11291127
elif isinstance(shape, tuple):
11301128
shape = Shape("polygon", shape)
11311129
## else shape assumed to be Shape-instance
@@ -1454,7 +1452,7 @@ def bgpic(self, picname=None):
14541452
"""Set background image or return name of current backgroundimage.
14551453
14561454
Optional argument:
1457-
picname -- a string, name of a gif-file or "nopic".
1455+
picname -- a string, name of an image file (PNG, GIF, PGM, and PPM) or "nopic".
14581456
14591457
If picname is a filename, set the corresponding image as background.
14601458
If picname is "nopic", delete backgroundimage, if present.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added support for other image formats (PNG, PGM, and PPM) to the turtle module. Patch by Shin-myoung-serp.

Parser/lexer/lexer.c

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -329,11 +329,7 @@ verify_identifier(struct tok_state *tok)
329329
return 0;
330330
}
331331
Py_ssize_t invalid = _PyUnicode_ScanIdentifier(s);
332-
if (invalid < 0) {
333-
Py_DECREF(s);
334-
tok->done = E_ERROR;
335-
return 0;
336-
}
332+
assert(invalid >= 0);
337333
assert(PyUnicode_GET_LENGTH(s) > 0);
338334
if (invalid < PyUnicode_GET_LENGTH(s)) {
339335
Py_UCS4 ch = PyUnicode_READ_CHAR(s, invalid);

0 commit comments

Comments
 (0)
0