Skip to content

Commit 3c91201

Browse files
committed
Merge branch 'main' into windows-add-sysconfig-abiflags
2 parents 75b6c51 + d87e7f3 commit 3c91201

File tree

100 files changed

+3662
-1828
lines changed

Some content is hidden

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

100 files changed

+3662
-1828
lines changed

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::

Doc/library/decimal.rst

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1884,13 +1884,20 @@ the current thread.
18841884

18851885
If :func:`setcontext` has not been called before :func:`getcontext`, then
18861886
:func:`getcontext` will automatically create a new context for use in the
1887-
current thread.
1888-
1889-
The new context is copied from a prototype context called *DefaultContext*. To
1890-
control the defaults so that each thread will use the same values throughout the
1891-
application, directly modify the *DefaultContext* object. This should be done
1892-
*before* any threads are started so that there won't be a race condition between
1893-
threads calling :func:`getcontext`. For example::
1887+
current thread. New context objects have default values set from the
1888+
:data:`decimal.DefaultContext` object.
1889+
1890+
The :data:`sys.flags.thread_inherit_context` flag affects the context for
1891+
new threads. If the flag is false, new threads will start with an empty
1892+
context. In this case, :func:`getcontext` will create a new context object
1893+
when called and use the default values from *DefaultContext*. If the flag
1894+
is true, new threads will start with a copy of context from the caller of
1895+
:meth:`threading.Thread.start`.
1896+
1897+
To control the defaults so that each thread will use the same values throughout
1898+
the application, directly modify the *DefaultContext* object. This should be
1899+
done *before* any threads are started so that there won't be a race condition
1900+
between threads calling :func:`getcontext`. For example::
18941901

18951902
# Set applicationwide defaults for all threads about to be launched
18961903
DefaultContext.prec = 12

Doc/library/gzip.rst

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,7 @@ The module defines the following items:
122122
.. method:: peek(n)
123123

124124
Read *n* uncompressed bytes without advancing the file position.
125-
At most one single read on the compressed stream is done to satisfy
126-
the call. The number of bytes returned may be more or less than
127-
requested.
125+
The number of bytes returned may be more or less than requested.
128126

129127
.. note:: While calling :meth:`peek` does not change the file position of
130128
the :class:`GzipFile`, it may change the position of the underlying

Doc/library/pathlib.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -871,6 +871,12 @@ conforming to :rfc:`8089`.
871871

872872
.. versionadded:: 3.13
873873

874+
.. versionchanged:: next
875+
If a URL authority (e.g. a hostname) is present and resolves to a local
876+
address, it is discarded. If an authority is present and *doesn't*
877+
resolve to a local address, then on Windows a UNC path is returned (as
878+
before), and on other platforms a :exc:`ValueError` is raised.
879+
874880

875881
.. method:: Path.as_uri()
876882

Doc/library/re.rst

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -250,14 +250,23 @@ The special characters are:
250250
``[a\-z]``) or if it's placed as the first or last character
251251
(e.g. ``[-a]`` or ``[a-]``), it will match a literal ``'-'``.
252252

253-
* Special characters lose their special meaning inside sets. For example,
253+
* Special characters except backslash lose their special meaning inside sets.
254+
For example,
254255
``[(+*)]`` will match any of the literal characters ``'('``, ``'+'``,
255256
``'*'``, or ``')'``.
256257

257258
.. index:: single: \ (backslash); in regular expressions
258259

259-
* Character classes such as ``\w`` or ``\S`` (defined below) are also accepted
260-
inside a set, although the characters they match depend on the flags_ used.
260+
* Backslash either escapes characters which have special meaning in a set
261+
such as ``'-'``, ``']'``, ``'^'`` and ``'\\'`` itself or signals
262+
a special sequence which represents a single character such as
263+
``\xa0`` or ``\n`` or a character class such as ``\w`` or ``\S``
264+
(defined below).
265+
Note that ``\b`` represents a single "backspace" character,
266+
not a word boundary as outside a set, and numeric escapes
267+
such as ``\1`` are always octal escapes, not group references.
268+
Special sequences which do not match a single character such as ``\A``
269+
and ``\Z`` are not allowed.
261270

262271
.. index:: single: ^ (caret); in regular expressions
263272

Doc/library/sys.rst

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,8 @@ always available. Unless explicitly noted otherwise, all variables are read-only
535535
.. data:: flags
536536

537537
The :term:`named tuple` *flags* exposes the status of command line
538-
flags. The attributes are read only.
538+
flags. Flags should only be accessed only by name and not by index. The
539+
attributes are read only.
539540

540541
.. list-table::
541542

@@ -594,6 +595,18 @@ always available. Unless explicitly noted otherwise, all variables are read-only
594595
* - .. attribute:: flags.warn_default_encoding
595596
- :option:`-X warn_default_encoding <-X>`
596597

598+
* - .. attribute:: flags.gil
599+
- :option:`-X gil <-X>` and :envvar:`PYTHON_GIL`
600+
601+
* - .. attribute:: flags.thread_inherit_context
602+
- :option:`-X thread_inherit_context <-X>` and
603+
:envvar:`PYTHON_THREAD_INHERIT_CONTEXT`
604+
605+
* - .. attribute:: flags.context_aware_warnings
606+
- :option:`-X context_aware_warnings <-X>` and
607+
:envvar:`PYTHON_CONTEXT_AWARE_WARNINGS`
608+
609+
597610
.. versionchanged:: 3.2
598611
Added ``quiet`` attribute for the new :option:`-q` flag.
599612

@@ -620,6 +633,15 @@ always available. Unless explicitly noted otherwise, all variables are read-only
620633
.. versionchanged:: 3.11
621634
Added the ``int_max_str_digits`` attribute.
622635

636+
.. versionchanged:: 3.13
637+
Added the ``gil`` attribute.
638+
639+
.. versionchanged:: 3.14
640+
Added the ``thread_inherit_context`` attribute.
641+
642+
.. versionchanged:: 3.14
643+
Added the ``context_aware_warnings`` attribute.
644+
623645

624646
.. data:: float_info
625647

0 commit comments

Comments
 (0)