Skip to content

Commit 101abe3

Browse files
committed
Merge branch 'main' into tstrings
2 parents d6c470c + 26ae05e commit 101abe3

File tree

118 files changed

+3862
-1911
lines changed

Some content is hidden

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

118 files changed

+3862
-1911
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

.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/typeobj.rst

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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/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/curses.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,8 +145,8 @@ importing the :func:`curses.wrapper` function and using it like this::
145145
v = i-10
146146
stdscr.addstr(i, 0, '10 divided by {} is {}'.format(v, 10/v))
147147

148-
stdscr.refresh()
149-
stdscr.getkey()
148+
stdscr.refresh()
149+
stdscr.getkey()
150150

151151
wrapper(main)
152152

Doc/howto/free-threading-python.rst

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,3 +152,33 @@ to re-enable it in a thread-safe way in the 3.14 release. This overhead is
152152
expected to be reduced in upcoming Python release. We are aiming for an
153153
overhead of 10% or less on the pyperformance suite compared to the default
154154
GIL-enabled build.
155+
156+
157+
Behavioral changes
158+
==================
159+
160+
This section describes CPython behavioural changes with the free-threaded
161+
build.
162+
163+
164+
Context variables
165+
-----------------
166+
167+
In the free-threaded build, the flag :data:`~sys.flags.thread_inherit_context`
168+
is set to true by default which causes threads created with
169+
:class:`threading.Thread` to start with a copy of the
170+
:class:`~contextvars.Context()` of the caller of
171+
:meth:`~threading.Thread.start`. In the default GIL-enabled build, the flag
172+
defaults to false so threads start with an
173+
empty :class:`~contextvars.Context()`.
174+
175+
176+
Warning filters
177+
---------------
178+
179+
In the free-threaded build, the flag :data:`~sys.flags.context_aware_warnings`
180+
is set to true by default. In the default GIL-enabled build, the flag defaults
181+
to false. If the flag is true then the :class:`warnings.catch_warnings`
182+
context manager uses a context variable for warning filters. If the flag is
183+
false then :class:`~warnings.catch_warnings` modifies the global filters list,
184+
which is not thread-safe. See the :mod:`warnings` module for more details.

Doc/includes/typestruct.h

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,11 @@ typedef struct _typeobject {
5454
iternextfunc tp_iternext;
5555

5656
/* Attribute descriptor and subclassing stuff */
57-
struct PyMethodDef *tp_methods;
58-
struct PyMemberDef *tp_members;
59-
struct PyGetSetDef *tp_getset;
57+
PyMethodDef *tp_methods;
58+
PyMemberDef *tp_members;
59+
PyGetSetDef *tp_getset;
6060
// Strong reference on a heap type, borrowed reference on a static type
61-
struct _typeobject *tp_base;
61+
PyTypeObject *tp_base;
6262
PyObject *tp_dict;
6363
descrgetfunc tp_descr_get;
6464
descrsetfunc tp_descr_set;
@@ -70,17 +70,26 @@ typedef struct _typeobject {
7070
inquiry tp_is_gc; /* For PyObject_IS_GC */
7171
PyObject *tp_bases;
7272
PyObject *tp_mro; /* method resolution order */
73-
PyObject *tp_cache;
74-
PyObject *tp_subclasses;
75-
PyObject *tp_weaklist;
73+
PyObject *tp_cache; /* no longer used */
74+
void *tp_subclasses; /* for static builtin types this is an index */
75+
PyObject *tp_weaklist; /* not used for static builtin types */
7676
destructor tp_del;
7777

78-
/* Type attribute cache version tag. Added in version 2.6 */
78+
/* Type attribute cache version tag. Added in version 2.6.
79+
* If zero, the cache is invalid and must be initialized.
80+
*/
7981
unsigned int tp_version_tag;
8082

8183
destructor tp_finalize;
8284
vectorcallfunc tp_vectorcall;
8385

8486
/* bitset of which type-watchers care about this type */
8587
unsigned char tp_watched;
88+
89+
/* Number of tp_version_tag values used.
90+
* Set to _Py_ATTR_CACHE_UNUSED if the attribute cache is
91+
* disabled for this type (e.g. due to custom MRO entries).
92+
* Otherwise, limited to MAX_VERSIONS_PER_CLASS (defined elsewhere).
93+
*/
94+
uint16_t tp_versions_used;
8695
} PyTypeObject;

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

Doc/library/contextlib.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ Functions and classes provided:
4949

5050
While many objects natively support use in with statements, sometimes a
5151
resource needs to be managed that isn't a context manager in its own right,
52-
and doesn't implement a ``close()`` method for use with ``contextlib.closing``
52+
and doesn't implement a ``close()`` method for use with ``contextlib.closing``.
5353

5454
An abstract example would be the following to ensure correct resource
5555
management::

0 commit comments

Comments
 (0)