Skip to content

Commit db2876d

Browse files
authored
Merge branch 'main' into gh-125866-again
2 parents c570e2a + 281fc33 commit db2876d

File tree

99 files changed

+1053
-457
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+1053
-457
lines changed

.azure-pipelines/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
trigger: ['main', '3.13', '3.12', '3.11', '3.10', '3.9', '3.8']
1+
trigger: ['main', '3.*']
22

33
jobs:
44
- job: Prebuild

.editorconfig

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
root = true
22

3-
[*.{py,c,cpp,h,js,rst,md,yml}]
3+
[*.{py,c,cpp,h,js,rst,md,yml,yaml}]
44
trim_trailing_whitespace = true
55
insert_final_newline = true
66
indent_style = space
@@ -11,5 +11,5 @@ indent_size = 4
1111
[*.rst]
1212
indent_size = 3
1313

14-
[*.{js,yml}]
14+
[*.{js,yml,yaml}]
1515
indent_size = 2

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,10 @@ Please read this comment in its entirety. It's quite important.
77
It should be in the following format:
88
99
```
10-
gh-NNNNN: Summary of the changes made
10+
gh-NNNNNN: Summary of the changes made
1111
```
1212
13-
Where: gh-NNNNN refers to the GitHub issue number.
13+
Where: gh-NNNNNN refers to the GitHub issue number.
1414
1515
Most PRs will require an issue number. Trivial changes, like fixing a typo, do not need an issue.
1616
@@ -20,11 +20,11 @@ If this is a backport PR (PR made against branches other than `main`),
2020
please ensure that the PR title is in the following format:
2121
2222
```
23-
[X.Y] <title from the original PR> (GH-NNNN)
23+
[X.Y] <title from the original PR> (GH-NNNNNN)
2424
```
2525
26-
Where: [X.Y] is the branch name, e.g. [3.6].
26+
Where: [X.Y] is the branch name, for example: [3.13].
2727
28-
GH-NNNN refers to the PR number from `main`.
28+
GH-NNNNNN refers to the PR number from `main`.
2929
3030
-->

Doc/c-api/gcsupport.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@ the garbage collector.
277277
278278
Type of the visitor function to be passed to :c:func:`PyUnstable_GC_VisitObjects`.
279279
*arg* is the same as the *arg* passed to ``PyUnstable_GC_VisitObjects``.
280-
Return ``0`` to continue iteration, return ``1`` to stop iteration. Other return
280+
Return ``1`` to continue iteration, return ``0`` to stop iteration. Other return
281281
values are reserved for now so behavior on returning anything else is undefined.
282282
283283
.. versionadded:: 3.12

Doc/c-api/typeobj.rst

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -611,7 +611,7 @@ and :c:data:`PyType_Type` effectively act as defaults.)
611611
Note that the :c:member:`~PyVarObject.ob_size` field may later be used for
612612
other purposes. For example, :py:type:`int` instances use the bits of
613613
:c:member:`~PyVarObject.ob_size` in an implementation-defined
614-
way; the underlying storage and its size should be acessed using
614+
way; the underlying storage and its size should be accessed using
615615
:c:func:`PyLong_Export`.
616616

617617
.. note::
@@ -703,10 +703,13 @@ and :c:data:`PyType_Type` effectively act as defaults.)
703703

704704
.. code-block:: c
705705
706-
static void foo_dealloc(foo_object *self) {
706+
static void
707+
foo_dealloc(PyObject *op)
708+
{
709+
foo_object *self = (foo_object *) op;
707710
PyObject_GC_UnTrack(self);
708711
Py_CLEAR(self->ref);
709-
Py_TYPE(self)->tp_free((PyObject *)self);
712+
Py_TYPE(self)->tp_free(self);
710713
}
711714
712715
Finally, if the type is heap allocated (:c:macro:`Py_TPFLAGS_HEAPTYPE`), the
@@ -717,10 +720,12 @@ and :c:data:`PyType_Type` effectively act as defaults.)
717720

718721
.. code-block:: c
719722
720-
static void foo_dealloc(foo_object *self) {
721-
PyTypeObject *tp = Py_TYPE(self);
723+
static void
724+
foo_dealloc(PyObject *op)
725+
{
726+
PyTypeObject *tp = Py_TYPE(op);
722727
// free references and buffers here
723-
tp->tp_free(self);
728+
tp->tp_free(op);
724729
Py_DECREF(tp);
725730
}
726731
@@ -1416,8 +1421,9 @@ and :c:data:`PyType_Type` effectively act as defaults.)
14161421
:mod:`!_thread` extension module::
14171422

14181423
static int
1419-
local_traverse(localobject *self, visitproc visit, void *arg)
1424+
local_traverse(PyObject *op, visitproc visit, void *arg)
14201425
{
1426+
localobject *self = (localobject *) op;
14211427
Py_VISIT(self->args);
14221428
Py_VISIT(self->kw);
14231429
Py_VISIT(self->dict);
@@ -1511,8 +1517,9 @@ and :c:data:`PyType_Type` effectively act as defaults.)
15111517
members to ``NULL``, as in the following example::
15121518

15131519
static int
1514-
local_clear(localobject *self)
1520+
local_clear(PyObject *op)
15151521
{
1522+
localobject *self = (localobject *) op;
15161523
Py_CLEAR(self->key);
15171524
Py_CLEAR(self->args);
15181525
Py_CLEAR(self->kw);

Doc/c-api/unicode.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -622,7 +622,7 @@ APIs:
622622
623623
On error, set *\*p_left* to ``NULL`` and set an exception.
624624
625-
On sucess, set *\*p_left* to a new strong reference to the result.
625+
On success, set *\*p_left* to a new strong reference to the result.
626626
627627
628628
.. c:function:: void PyUnicode_AppendAndDel(PyObject **p_left, PyObject *right)

Doc/deprecations/pending-removal-in-3.16.rst

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ Pending removal in Python 3.16
3232
* :class:`asyncio.WindowsProactorEventLoopPolicy`
3333
* :func:`asyncio.get_event_loop_policy`
3434
* :func:`asyncio.set_event_loop_policy`
35-
* :func:`asyncio.set_event_loop`
3635

3736
Users should use :func:`asyncio.run` or :class:`asyncio.Runner` with
3837
*loop_factory* to use the desired event loop implementation.

Doc/extending/newtypes.rst

Lines changed: 43 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -70,22 +70,24 @@ object itself needs to be freed here as well. Here is an example of this
7070
function::
7171

7272
static void
73-
newdatatype_dealloc(newdatatypeobject *obj)
73+
newdatatype_dealloc(PyObject *op)
7474
{
75-
free(obj->obj_UnderlyingDatatypePtr);
76-
Py_TYPE(obj)->tp_free((PyObject *)obj);
75+
newdatatypeobject *self = (newdatatypeobject *) op;
76+
free(self->obj_UnderlyingDatatypePtr);
77+
Py_TYPE(self)->tp_free(self);
7778
}
7879

7980
If your type supports garbage collection, the destructor should call
8081
:c:func:`PyObject_GC_UnTrack` before clearing any member fields::
8182

8283
static void
83-
newdatatype_dealloc(newdatatypeobject *obj)
84+
newdatatype_dealloc(PyObject *op)
8485
{
85-
PyObject_GC_UnTrack(obj);
86-
Py_CLEAR(obj->other_obj);
86+
newdatatypeobject *self = (newdatatypeobject *) op;
87+
PyObject_GC_UnTrack(op);
88+
Py_CLEAR(self->other_obj);
8789
...
88-
Py_TYPE(obj)->tp_free((PyObject *)obj);
90+
Py_TYPE(self)->tp_free(self);
8991
}
9092

9193
.. index::
@@ -117,17 +119,19 @@ done. This can be done using the :c:func:`PyErr_Fetch` and
117119
PyErr_Fetch(&err_type, &err_value, &err_traceback);
118120

119121
cbresult = PyObject_CallNoArgs(self->my_callback);
120-
if (cbresult == NULL)
121-
PyErr_WriteUnraisable(self->my_callback);
122-
else
122+
if (cbresult == NULL) {
123+
PyErr_WriteUnraisable(self->my_callback);
124+
}
125+
else {
123126
Py_DECREF(cbresult);
127+
}
124128

125129
/* This restores the saved exception state */
126130
PyErr_Restore(err_type, err_value, err_traceback);
127131

128132
Py_DECREF(self->my_callback);
129133
}
130-
Py_TYPE(obj)->tp_free((PyObject*)self);
134+
Py_TYPE(self)->tp_free(self);
131135
}
132136

133137
.. note::
@@ -168,10 +172,11 @@ representation of the instance for which it is called. Here is a simple
168172
example::
169173

170174
static PyObject *
171-
newdatatype_repr(newdatatypeobject *obj)
175+
newdatatype_repr(PyObject *op)
172176
{
177+
newdatatypeobject *self = (newdatatypeobject *) op;
173178
return PyUnicode_FromFormat("Repr-ified_newdatatype{{size:%d}}",
174-
obj->obj_UnderlyingDatatypePtr->size);
179+
self->obj_UnderlyingDatatypePtr->size);
175180
}
176181

177182
If no :c:member:`~PyTypeObject.tp_repr` handler is specified, the interpreter will supply a
@@ -188,10 +193,11 @@ used instead.
188193
Here is a simple example::
189194

190195
static PyObject *
191-
newdatatype_str(newdatatypeobject *obj)
196+
newdatatype_str(PyObject *op)
192197
{
198+
newdatatypeobject *self = (newdatatypeobject *) op;
193199
return PyUnicode_FromFormat("Stringified_newdatatype{{size:%d}}",
194-
obj->obj_UnderlyingDatatypePtr->size);
200+
self->obj_UnderlyingDatatypePtr->size);
195201
}
196202

197203

@@ -329,16 +335,16 @@ method of a class would be called.
329335
Here is an example::
330336

331337
static PyObject *
332-
newdatatype_getattr(newdatatypeobject *obj, char *name)
338+
newdatatype_getattr(PyObject *op, char *name)
333339
{
334-
if (strcmp(name, "data") == 0)
335-
{
336-
return PyLong_FromLong(obj->data);
340+
newdatatypeobject *self = (newdatatypeobject *) op;
341+
if (strcmp(name, "data") == 0) {
342+
return PyLong_FromLong(self->data);
337343
}
338344

339345
PyErr_Format(PyExc_AttributeError,
340346
"'%.100s' object has no attribute '%.400s'",
341-
Py_TYPE(obj)->tp_name, name);
347+
Py_TYPE(self)->tp_name, name);
342348
return NULL;
343349
}
344350

@@ -349,7 +355,7 @@ example that simply raises an exception; if this were really all you wanted, the
349355
:c:member:`~PyTypeObject.tp_setattr` handler should be set to ``NULL``. ::
350356

351357
static int
352-
newdatatype_setattr(newdatatypeobject *obj, char *name, PyObject *v)
358+
newdatatype_setattr(PyObject *op, char *name, PyObject *v)
353359
{
354360
PyErr_Format(PyExc_RuntimeError, "Read-only attribute: %s", name);
355361
return -1;
@@ -379,8 +385,10 @@ Here is a sample implementation, for a datatype that is considered equal if the
379385
size of an internal pointer is equal::
380386

381387
static PyObject *
382-
newdatatype_richcmp(newdatatypeobject *obj1, newdatatypeobject *obj2, int op)
388+
newdatatype_richcmp(PyObject *lhs, PyObject *rhs, int op)
383389
{
390+
newdatatypeobject *obj1 = (newdatatypeobject *) lhs;
391+
newdatatypeobject *obj2 = (newdatatypeobject *) rhs;
384392
PyObject *result;
385393
int c, size1, size2;
386394

@@ -399,8 +407,7 @@ size of an internal pointer is equal::
399407
case Py_GE: c = size1 >= size2; break;
400408
}
401409
result = c ? Py_True : Py_False;
402-
Py_INCREF(result);
403-
return result;
410+
return Py_NewRef(result);
404411
}
405412

406413

@@ -439,12 +446,14 @@ This function, if you choose to provide it, should return a hash number for an
439446
instance of your data type. Here is a simple example::
440447

441448
static Py_hash_t
442-
newdatatype_hash(newdatatypeobject *obj)
449+
newdatatype_hash(PyObject *op)
443450
{
451+
newdatatypeobject *self = (newdatatypeobject *) op;
444452
Py_hash_t result;
445-
result = obj->some_size + 32767 * obj->some_number;
446-
if (result == -1)
447-
result = -2;
453+
result = self->some_size + 32767 * self->some_number;
454+
if (result == -1) {
455+
result = -2;
456+
}
448457
return result;
449458
}
450459

@@ -478,8 +487,9 @@ This function takes three arguments:
478487
Here is a toy ``tp_call`` implementation::
479488

480489
static PyObject *
481-
newdatatype_call(newdatatypeobject *obj, PyObject *args, PyObject *kwds)
490+
newdatatype_call(PyObject *op, PyObject *args, PyObject *kwds)
482491
{
492+
newdatatypeobject *self = (newdatatypeobject *) op;
483493
PyObject *result;
484494
const char *arg1;
485495
const char *arg2;
@@ -490,7 +500,7 @@ Here is a toy ``tp_call`` implementation::
490500
}
491501
result = PyUnicode_FromFormat(
492502
"Returning -- value: [%d] arg1: [%s] arg2: [%s] arg3: [%s]\n",
493-
obj->obj_UnderlyingDatatypePtr->size,
503+
self->obj_UnderlyingDatatypePtr->size,
494504
arg1, arg2, arg3);
495505
return result;
496506
}
@@ -563,12 +573,12 @@ The only further addition is that ``tp_dealloc`` needs to clear any weak
563573
references (by calling :c:func:`PyObject_ClearWeakRefs`)::
564574

565575
static void
566-
Trivial_dealloc(TrivialObject *self)
576+
Trivial_dealloc(PyObject *op)
567577
{
568578
/* Clear weakrefs first before calling any destructors */
569-
PyObject_ClearWeakRefs((PyObject *) self);
579+
PyObject_ClearWeakRefs(op);
570580
/* ... remainder of destruction code omitted for brevity ... */
571-
Py_TYPE(self)->tp_free((PyObject *) self);
581+
Py_TYPE(op)->tp_free(op);
572582
}
573583

574584

Doc/howto/logging-cookbook.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -626,6 +626,19 @@ which, when run, will produce:
626626
of each message with the handler's level, and only passes a message to a
627627
handler if it's appropriate to do so.
628628

629+
.. versionchanged:: next
630+
The :class:`QueueListener` can be started (and stopped) via the
631+
:keyword:`with` statement. For example:
632+
633+
.. code-block:: python
634+
635+
with QueueListener(que, handler) as listener:
636+
# The queue listener automatically starts
637+
# when the 'with' block is entered.
638+
pass
639+
# The queue listener automatically stops once
640+
# the 'with' block is exited.
641+
629642
.. _network-logging:
630643

631644
Sending and receiving logging events across a network

Doc/library/annotationlib.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -303,12 +303,12 @@ Functions
303303
.. function:: get_annotate_function(obj)
304304

305305
Retrieve the :term:`annotate function` for *obj*. Return :const:`!None`
306-
if *obj* does not have an annotate function.
306+
if *obj* does not have an annotate function. *obj* may be a class, function,
307+
module, or a namespace dictionary for a class. The last case is useful during
308+
class creation, e.g. in the ``__new__`` method of a metaclass.
307309

308310
This is usually equivalent to accessing the :attr:`~object.__annotate__`
309-
attribute of *obj*, but direct access to the attribute may return the wrong
310-
object in certain situations involving metaclasses. This function should be
311-
used instead of accessing the attribute directly.
311+
attribute of *obj*, but access through this public function is preferred.
312312

313313
.. versionadded:: 3.14
314314

0 commit comments

Comments
 (0)