Skip to content

Commit 3b3776e

Browse files
authored
Merge branch 'python:main' into windows-aarch64-runners
2 parents e9688bf + af29d5c commit 3b3776e

24 files changed

+239
-159
lines changed

Doc/library/importlib.metadata.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ While the module level API described above is the most common and convenient usa
422422
you can get all of that information from the :class:`!Distribution` class.
423423
:class:`!Distribution` is an abstract object that represents the metadata for
424424
a Python `Distribution Package <https://packaging.python.org/en/latest/glossary/#term-Distribution-Package>`_.
425-
You can get the concreate :class:`!Distribution` subclass instance for an installed
425+
You can get the concrete :class:`!Distribution` subclass instance for an installed
426426
distribution package by calling the :func:`distribution` function::
427427

428428
>>> from importlib.metadata import distribution # doctest: +SKIP

Doc/library/mailbox.rst

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,12 +587,27 @@ Supported mailbox formats are Maildir, mbox, MH, Babyl, and MMDF.
587587
remarks:
588588

589589

590-
.. method:: get_file(key)
590+
.. method:: get_bytes(key, from_=False)
591+
592+
Note: This method has an extra parameter (*from_*) compared with other classes.
593+
The first line of an mbox file entry is the Unix "From " line.
594+
If *from_* is False, the first line of the file is dropped.
595+
596+
.. method:: get_file(key, from_=False)
591597

592598
Using the file after calling :meth:`~Mailbox.flush` or
593599
:meth:`~Mailbox.close` on the :class:`!mbox` instance may yield
594600
unpredictable results or raise an exception.
595601

602+
Note: This method has an extra parameter (*from_*) compared with other classes.
603+
The first line of an mbox file entry is the Unix "From " line.
604+
If *from_* is False, the first line of the file is dropped.
605+
606+
.. method:: get_string(key, from_=False)
607+
608+
Note: This method has an extra parameter (*from_*) compared with other classes.
609+
The first line of an mbox file entry is the Unix "From " line.
610+
If *from_* is False, the first line of the file is dropped.
596611

597612
.. method:: lock()
598613
unlock()
@@ -851,12 +866,22 @@ Supported mailbox formats are Maildir, mbox, MH, Babyl, and MMDF.
851866
remarks:
852867

853868

854-
.. method:: get_file(key)
869+
.. method:: get_bytes(key, from_=False)
870+
871+
Note: This method has an extra parameter (*from_*) compared with other classes.
872+
The first line of an mbox file entry is the Unix "From " line.
873+
If *from_* is False, the first line of the file is dropped.
874+
875+
.. method:: get_file(key, from_=False)
855876

856877
Using the file after calling :meth:`~Mailbox.flush` or
857878
:meth:`~Mailbox.close` on the :class:`!MMDF` instance may yield
858879
unpredictable results or raise an exception.
859880

881+
Note: This method has an extra parameter (*from_*) compared with other classes.
882+
The first line of an mbox file entry is the Unix "From " line.
883+
If *from_* is False, the first line of the file is dropped.
884+
860885

861886
.. method:: lock()
862887
unlock()

Doc/library/urllib.request.rst

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,48 +1215,49 @@ In addition to the examples below, more examples are given in
12151215
:ref:`urllib-howto`.
12161216

12171217
This example gets the python.org main page and displays the first 300 bytes of
1218-
it. ::
1218+
it::
12191219

12201220
>>> import urllib.request
12211221
>>> with urllib.request.urlopen('http://www.python.org/') as f:
12221222
... print(f.read(300))
12231223
...
1224-
b'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
1225-
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\n\n\n<html
1226-
xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">\n\n<head>\n
1227-
<meta http-equiv="content-type" content="text/html; charset=utf-8" />\n
1228-
<title>Python Programming '
1224+
b'<!doctype html>\n<!--[if lt IE 7]> <html class="no-js ie6 lt-ie7 lt-ie8 lt-ie9"> <![endif]-->\n<!--[if IE 7]> <html class="no-js ie7 lt-ie8 lt-ie9"> <![endif]-->\n<!--[if IE 8]> <html class="no-js ie8 lt-ie9">
12291225

12301226
Note that urlopen returns a bytes object. This is because there is no way
12311227
for urlopen to automatically determine the encoding of the byte stream
12321228
it receives from the HTTP server. In general, a program will decode
12331229
the returned bytes object to string once it determines or guesses
12341230
the appropriate encoding.
12351231

1236-
The following W3C document, https://www.w3.org/International/O-charset\ , lists
1237-
the various ways in which an (X)HTML or an XML document could have specified its
1232+
The following HTML spec document, https://html.spec.whatwg.org/#charset, lists
1233+
the various ways in which an HTML or an XML document could have specified its
12381234
encoding information.
12391235

1236+
For additional information, see the W3C document: https://www.w3.org/International/questions/qa-html-encoding-declarations.
1237+
12401238
As the python.org website uses *utf-8* encoding as specified in its meta tag, we
1241-
will use the same for decoding the bytes object. ::
1239+
will use the same for decoding the bytes object::
12421240

12431241
>>> with urllib.request.urlopen('http://www.python.org/') as f:
12441242
... print(f.read(100).decode('utf-8'))
12451243
...
1246-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
1247-
"http://www.w3.org/TR/xhtml1/DTD/xhtm
1244+
<!doctype html>
1245+
<!--[if lt IE 7]> <html class="no-js ie6 lt-ie7 lt-ie8 lt-ie9"> <![endif]-->
1246+
<!-
12481247

12491248
It is also possible to achieve the same result without using the
1250-
:term:`context manager` approach. ::
1249+
:term:`context manager` approach::
12511250

12521251
>>> import urllib.request
12531252
>>> f = urllib.request.urlopen('http://www.python.org/')
12541253
>>> try:
12551254
... print(f.read(100).decode('utf-8'))
12561255
... finally:
12571256
... f.close()
1258-
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
1259-
"http://www.w3.org/TR/xhtml1/DTD/xhtm
1257+
...
1258+
<!doctype html>
1259+
<!--[if lt IE 7]> <html class="no-js ie6 lt-ie7 lt-ie8 lt-ie9"> <![endif]-->
1260+
<!--
12601261

12611262
In the following example, we are sending a data-stream to the stdin of a CGI
12621263
and reading the data it returns to us. Note that this example will only work

Doc/reference/compound_stmts.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1222,7 +1222,7 @@ A function definition defines a user-defined function object (see section
12221222
parameter_list_no_posonly: `defparameter` ("," `defparameter`)* ["," [`parameter_list_starargs`]]
12231223
: | `parameter_list_starargs`
12241224
parameter_list_starargs: "*" [`star_parameter`] ("," `defparameter`)* ["," [`parameter_star_kwargs`]]
1225-
: "*" ("," `defparameter`)+ ["," [`parameter_star_kwargs`]]
1225+
: | "*" ("," `defparameter`)+ ["," [`parameter_star_kwargs`]]
12261226
: | `parameter_star_kwargs`
12271227
parameter_star_kwargs: "**" `parameter` [","]
12281228
parameter: `identifier` [":" `expression`]

Lib/test/test_ast/test_ast.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3238,6 +3238,18 @@ def get_match_case_values(node):
32383238
values = get_match_case_values(case.pattern)
32393239
self.assertListEqual(constants, values)
32403240

3241+
def test_match_case_not_folded_in_unoptimized_ast(self):
3242+
src = textwrap.dedent("""
3243+
match a:
3244+
case 1+2j:
3245+
pass
3246+
""")
3247+
3248+
unfolded = "MatchValue(value=BinOp(left=Constant(value=1), op=Add(), right=Constant(value=2j))"
3249+
folded = "MatchValue(value=Constant(value=(1+2j)))"
3250+
for optval in (0, 1, 2):
3251+
self.assertIn(folded if optval else unfolded, ast.dump(ast.parse(src, optimize=optval)))
3252+
32413253

32423254
if __name__ == '__main__':
32433255
if len(sys.argv) > 1 and sys.argv[1] == '--snapshot-update':

Lib/test/test_capi/test_bytearray.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ class CAPITest(unittest.TestCase):
2020
def test_check(self):
2121
# Test PyByteArray_Check()
2222
check = _testlimitedcapi.bytearray_check
23+
self.assertTrue(check(bytearray(b'')))
2324
self.assertTrue(check(bytearray(b'abc')))
2425
self.assertFalse(check(b'abc'))
2526
self.assertTrue(check(ByteArraySubclass(b'abc')))
@@ -33,6 +34,7 @@ def test_check(self):
3334
def test_checkexact(self):
3435
# Test PyByteArray_CheckExact()
3536
check = _testlimitedcapi.bytearray_checkexact
37+
self.assertTrue(check(bytearray(b'')))
3638
self.assertTrue(check(bytearray(b'abc')))
3739
self.assertFalse(check(b'abc'))
3840
self.assertFalse(check(ByteArraySubclass(b'abc')))
@@ -78,7 +80,7 @@ def test_fromobject(self):
7880
def test_size(self):
7981
# Test PyByteArray_Size()
8082
size = _testlimitedcapi.bytearray_size
81-
83+
self.assertEqual(size(bytearray(b'')), 0)
8284
self.assertEqual(size(bytearray(b'abc')), 3)
8385
self.assertEqual(size(ByteArraySubclass(b'abc')), 3)
8486

@@ -89,7 +91,7 @@ def test_size(self):
8991
def test_asstring(self):
9092
"""Test PyByteArray_AsString()"""
9193
asstring = _testlimitedcapi.bytearray_asstring
92-
94+
self.assertEqual(asstring(bytearray(b''), 1), b'\0')
9395
self.assertEqual(asstring(bytearray(b'abc'), 4), b'abc\0')
9496
self.assertEqual(asstring(ByteArraySubclass(b'abc'), 4), b'abc\0')
9597
self.assertEqual(asstring(bytearray(b'abc\0def'), 8), b'abc\0def\0')
@@ -105,6 +107,7 @@ def test_concat(self):
105107
ba = bytearray(b'abc')
106108
self.assertEqual(concat(ba, b'def'), bytearray(b'abcdef'))
107109
self.assertEqual(ba, b'abc')
110+
self.assertEqual(concat(ba, ba), bytearray(b'abcabc'))
108111

109112
self.assertEqual(concat(b'abc', b'def'), bytearray(b'abcdef'))
110113
self.assertEqual(concat(b'a\0b', b'c\0d'), bytearray(b'a\0bc\0d'))

Lib/test/test_tracemalloc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,7 @@ def test_stop_untrack(self):
11141114
@threading_helper.requires_working_threading()
11151115
# gh-128679: Test crash on a debug build (especially on FreeBSD).
11161116
@unittest.skipIf(support.Py_DEBUG, 'need release build')
1117+
@support.skip_if_sanitizer('gh-131566: race when setting allocator', thread=True)
11171118
def test_tracemalloc_track_race(self):
11181119
# gh-128679: Test fix for tracemalloc.stop() race condition
11191120
_testcapi.tracemalloc_track_race()

Modules/_asynciomodule.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2121,16 +2121,17 @@ TaskStepMethWrapper_traverse(PyObject *op,
21212121
}
21222122

21232123
static PyObject *
2124-
TaskStepMethWrapper_get___self__(TaskStepMethWrapper *o, void *Py_UNUSED(ignored))
2124+
TaskStepMethWrapper_get___self__(PyObject *op, void *Py_UNUSED(closure))
21252125
{
2126+
TaskStepMethWrapper *o = (TaskStepMethWrapper*)op;
21262127
if (o->sw_task) {
21272128
return Py_NewRef(o->sw_task);
21282129
}
21292130
Py_RETURN_NONE;
21302131
}
21312132

21322133
static PyGetSetDef TaskStepMethWrapper_getsetlist[] = {
2133-
{"__self__", (getter)TaskStepMethWrapper_get___self__, NULL, NULL},
2134+
{"__self__", TaskStepMethWrapper_get___self__, NULL, NULL},
21342135
{NULL} /* Sentinel */
21352136
};
21362137

Modules/_multiprocessing/semaphore.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class _multiprocessing.SemLock "SemLockObject *" "&_PyMp_SemLockType"
6565
#define SEM_UNLINK(name) 0
6666

6767
static int
68-
_GetSemaphoreValue(HANDLE handle, long *value)
68+
_GetSemaphoreValue(HANDLE handle, int *value)
6969
{
7070
long previous;
7171

Modules/_testbuffer.c

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1586,8 +1586,9 @@ ptr_from_index(Py_buffer *base, Py_ssize_t index)
15861586
}
15871587

15881588
static PyObject *
1589-
ndarray_item(NDArrayObject *self, Py_ssize_t index)
1589+
ndarray_item(PyObject *op, Py_ssize_t index)
15901590
{
1591+
NDArrayObject *self = (NDArrayObject *)op;
15911592
ndbuf_t *ndbuf = self->head;
15921593
Py_buffer *base = &ndbuf->base;
15931594
char *ptr;
@@ -1801,7 +1802,7 @@ ndarray_subscript(PyObject *op, PyObject *key)
18011802
Py_ssize_t index = PyLong_AsSsize_t(key);
18021803
if (index == -1 && PyErr_Occurred())
18031804
return NULL;
1804-
return ndarray_item(self, index);
1805+
return ndarray_item(op, index);
18051806
}
18061807

18071808
nd = (NDArrayObject *)ndarray_new(&NDArray_Type, NULL, NULL);
@@ -1966,10 +1967,10 @@ static PyMappingMethods ndarray_as_mapping = {
19661967
};
19671968

19681969
static PySequenceMethods ndarray_as_sequence = {
1969-
0, /* sq_length */
1970-
0, /* sq_concat */
1971-
0, /* sq_repeat */
1972-
(ssizeargfunc)ndarray_item, /* sq_item */
1970+
0, /* sq_length */
1971+
0, /* sq_concat */
1972+
0, /* sq_repeat */
1973+
ndarray_item, /* sq_item */
19731974
};
19741975

19751976

@@ -2742,16 +2743,17 @@ staticarray_init(PyObject *self, PyObject *args, PyObject *kwds)
27422743
}
27432744

27442745
static void
2745-
staticarray_dealloc(StaticArrayObject *self)
2746+
staticarray_dealloc(PyObject *self)
27462747
{
27472748
PyObject_Free(self);
27482749
}
27492750

27502751
/* Return a buffer for a PyBUF_FULL_RO request. Flags are not checked,
27512752
which makes this object a non-compliant exporter! */
27522753
static int
2753-
staticarray_getbuf(StaticArrayObject *self, Py_buffer *view, int flags)
2754+
staticarray_getbuf(PyObject *op, Py_buffer *view, int flags)
27542755
{
2756+
StaticArrayObject *self = (StaticArrayObject *)op;
27552757
*view = static_buffer;
27562758

27572759
if (self->legacy_mode) {
@@ -2765,7 +2767,7 @@ staticarray_getbuf(StaticArrayObject *self, Py_buffer *view, int flags)
27652767
}
27662768

27672769
static PyBufferProcs staticarray_as_buffer = {
2768-
(getbufferproc)staticarray_getbuf, /* bf_getbuffer */
2770+
staticarray_getbuf, /* bf_getbuffer */
27692771
NULL, /* bf_releasebuffer */
27702772
};
27712773

@@ -2774,7 +2776,7 @@ static PyTypeObject StaticArray_Type = {
27742776
"staticarray", /* Name of this type */
27752777
sizeof(StaticArrayObject), /* Basic object size */
27762778
0, /* Item size for varobject */
2777-
(destructor)staticarray_dealloc, /* tp_dealloc */
2779+
staticarray_dealloc, /* tp_dealloc */
27782780
0, /* tp_vectorcall_offset */
27792781
0, /* tp_getattr */
27802782
0, /* tp_setattr */

0 commit comments

Comments
 (0)