Skip to content

Commit 07cb6e9

Browse files
authored
Merge branch 'main' into gh-144316-get_stack_trace
2 parents c0a8037 + dd0fde5 commit 07cb6e9

38 files changed

+1218
-360
lines changed

Doc/c-api/intro.rst

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,35 @@ complete listing.
167167

168168
.. versionadded:: 3.3
169169

170+
.. c:macro:: Py_ALIGNED(num)
171+
172+
Specify alignment to *num* bytes on compilers that support it.
173+
174+
Consider using the C11 standard ``_Alignas`` specifier over this macro.
175+
176+
.. c:macro:: Py_ARITHMETIC_RIGHT_SHIFT(type, integer, positions)
177+
178+
Similar to ``integer >> positions``, but forces sign extension, as the C
179+
standard does not define whether a right-shift of a signed integer will
180+
perform sign extension or a zero-fill.
181+
182+
*integer* should be any signed integer type.
183+
*positions* is the number of positions to shift to the right.
184+
185+
Both *integer* and *positions* can be evaluated more than once;
186+
consequently, avoid directly passing a function call or some other
187+
operation with side-effects to this macro. Instead, store the result as a
188+
variable and then pass it.
189+
190+
*type* is unused and only kept for backwards compatibility. Historically,
191+
*type* was used to cast *integer*.
192+
193+
.. versionchanged:: 3.1
194+
195+
This macro is now valid for all signed integer types, not just those for
196+
which ``unsigned type`` is legal. As a result, *type* is no longer
197+
used.
198+
170199
.. c:macro:: Py_ALWAYS_INLINE
171200
172201
Ask the compiler to always inline a static inline function. The compiler can
@@ -189,6 +218,15 @@ complete listing.
189218

190219
.. versionadded:: 3.11
191220

221+
.. c:macro:: Py_CAN_START_THREADS
222+
223+
If this macro is defined, then the current system is able to start threads.
224+
225+
Currently, all systems supported by CPython (per :pep:`11`), with the
226+
exception of some WebAssembly platforms, support starting threads.
227+
228+
.. versionadded:: 3.13
229+
192230
.. c:macro:: Py_CHARMASK(c)
193231
194232
Argument must be a character or an integer in the range [-128, 127] or [0,
@@ -206,11 +244,35 @@ complete listing.
206244
.. versionchanged:: 3.8
207245
MSVC support was added.
208246

247+
.. c:macro:: Py_FORCE_EXPANSION(X)
248+
249+
This is equivalent to ``X``, which is useful for token-pasting in
250+
macros, as macro expansions in *X* are forcefully evaluated by the
251+
preprocessor.
252+
253+
.. c:macro:: Py_GCC_ATTRIBUTE(name)
254+
255+
Use a GCC attribute *name*, hiding it from compilers that don't support GCC
256+
attributes (such as MSVC).
257+
258+
This expands to ``__attribute__((name))`` on a GCC compiler, and expands
259+
to nothing on compilers that don't support GCC attributes.
260+
209261
.. c:macro:: Py_GETENV(s)
210262
211263
Like ``getenv(s)``, but returns ``NULL`` if :option:`-E` was passed on the
212264
command line (see :c:member:`PyConfig.use_environment`).
213265

266+
.. c:macro:: Py_LL(number)
267+
268+
Use *number* as a ``long long`` integer literal.
269+
270+
This usally expands to *number* followed by ``LL``, but will expand to some
271+
compiler-specific suffixes (such as ``I64``) on older compilers.
272+
273+
In modern versions of Python, this macro is not very useful, as C99 and
274+
later require the ``LL`` suffix to be valid for an integer.
275+
214276
.. c:macro:: Py_LOCAL(type)
215277
216278
Declare a function returning the specified *type* using a fast-calling
@@ -268,13 +330,37 @@ complete listing.
268330

269331
.. versionadded:: 3.11
270332

333+
.. c:macro:: Py_SAFE_DOWNCAST(value, larger, smaller)
334+
335+
Cast *value* to type *smaller* from type *larger*, validating that no
336+
information was lost.
337+
338+
On release builds of Python, this is roughly equivalent to
339+
``(smaller) value`` (in C++, ``static_cast<smaller>(value)`` will be
340+
used instead).
341+
342+
On debug builds (implying that :c:macro:`Py_DEBUG` is defined), this asserts
343+
that no information was lost with the cast from *larger* to *smaller*.
344+
345+
*value*, *larger*, and *smaller* may all be evaluated more than once in the
346+
expression; consequently, do not pass an expression with side-effects directly to
347+
this macro.
348+
271349
.. c:macro:: Py_STRINGIFY(x)
272350
273351
Convert ``x`` to a C string. E.g. ``Py_STRINGIFY(123)`` returns
274352
``"123"``.
275353

276354
.. versionadded:: 3.4
277355

356+
.. c:macro:: Py_ULL(number)
357+
358+
Similar to :c:macro:`Py_LL`, but *number* will be an ``unsigned long long``
359+
literal instead. This is done by appending ``U`` to the result of ``Py_LL``.
360+
361+
In modern versions of Python, this macro is not very useful, as C99 and
362+
later require the ``ULL``/``LLU`` suffixes to be valid for an integer.
363+
278364
.. c:macro:: Py_UNREACHABLE()
279365
280366
Use this when you have a code path that cannot be reached by design.
@@ -415,6 +501,16 @@ complete listing.
415501
This macro is intended for defining CPython's C API itself;
416502
extension modules should not use it for their own symbols.
417503

504+
.. c:macro:: Py_VA_COPY
505+
506+
This is a :term:`soft deprecated` alias to the C99-standard ``va_copy``
507+
function.
508+
509+
Historically, this would use a compiler-specific method to copy a ``va_list``.
510+
511+
.. versionchanged:: 3.6
512+
This is now an alias to ``va_copy``.
513+
418514

419515
.. _api-objects:
420516

Doc/glossary.rst

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -786,6 +786,19 @@ Glossary
786786
An object that both finds and loads a module; both a
787787
:term:`finder` and :term:`loader` object.
788788

789+
index
790+
A numeric value that represents the position of an element in
791+
a :term:`sequence`.
792+
793+
In Python, indexing starts at zero.
794+
For example, ``things[0]`` names the *first* element of ``things``;
795+
``things[1]`` names the second one.
796+
797+
In some contexts, Python allows negative indexes for counting from the
798+
end of a sequence, and indexing using :term:`slices <slice>`.
799+
800+
See also :term:`subscript`.
801+
789802
interactive
790803
Python has an interactive interpreter which means you can enter
791804
statements and expressions at the interpreter prompt, immediately
@@ -863,6 +876,9 @@ Glossary
863876
CPython does not guarantee :term:`thread-safe` behavior of iterator
864877
operations.
865878

879+
key
880+
A value that identifies an entry in a :term:`mapping`.
881+
See also :term:`subscript`.
866882

867883
key function
868884
A key function or collation function is a callable that returns a value
@@ -1417,10 +1433,11 @@ Glossary
14171433
chosen based on the type of a single argument.
14181434

14191435
slice
1420-
An object usually containing a portion of a :term:`sequence`. A slice is
1421-
created using the subscript notation, ``[]`` with colons between numbers
1422-
when several are given, such as in ``variable_name[1:3:5]``. The bracket
1423-
(subscript) notation uses :class:`slice` objects internally.
1436+
An object of type :class:`slice`, used to describe a portion of
1437+
a :term:`sequence`.
1438+
A slice object is created when using the :ref:`slicing <slicings>` form
1439+
of :ref:`subscript notation <subscriptions>`, with colons inside square
1440+
brackets, such as in ``variable_name[1:3:5]``.
14241441

14251442
soft deprecated
14261443
A soft deprecated API should not be used in new code,
@@ -1478,6 +1495,14 @@ Glossary
14781495

14791496
See also :term:`borrowed reference`.
14801497

1498+
subscript
1499+
The expression in square brackets of a
1500+
:ref:`subscription expression <subscriptions>`, for example,
1501+
the ``3`` in ``items[3]``.
1502+
Usually used to select an element of a container.
1503+
Also called a :term:`key` when subscripting a :term:`mapping`,
1504+
or an :term:`index` when subscripting a :term:`sequence`.
1505+
14811506
synchronization primitive
14821507
A basic building block for coordinating (synchronizing) the execution of
14831508
multiple threads to ensure :term:`thread-safe` access to shared resources.

Doc/library/contextlib.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,10 @@ Functions and classes provided:
564564
Raises :exc:`TypeError` instead of :exc:`AttributeError` if *cm*
565565
is not a context manager.
566566

567+
.. versionchanged:: next
568+
Added support for arbitrary descriptors :meth:`!__enter__` and
569+
:meth:`!__exit__`.
570+
567571
.. method:: push(exit)
568572

569573
Adds a context manager's :meth:`~object.__exit__` method to the callback stack.
@@ -582,6 +586,9 @@ Functions and classes provided:
582586
The passed in object is returned from the function, allowing this
583587
method to be used as a function decorator.
584588

589+
.. versionchanged:: next
590+
Added support for arbitrary descriptors :meth:`!__exit__`.
591+
585592
.. method:: callback(callback, /, *args, **kwds)
586593

587594
Accepts an arbitrary callback function and arguments and adds it to
@@ -639,11 +646,17 @@ Functions and classes provided:
639646
Raises :exc:`TypeError` instead of :exc:`AttributeError` if *cm*
640647
is not an asynchronous context manager.
641648

649+
.. versionchanged:: next
650+
Added support for arbitrary descriptors :meth:`!__aenter__` and :meth:`!__aexit__`.
651+
642652
.. method:: push_async_exit(exit)
643653

644654
Similar to :meth:`ExitStack.push` but expects either an asynchronous context manager
645655
or a coroutine function.
646656

657+
.. versionchanged:: next
658+
Added support for arbitrary descriptors :meth:`!__aexit__`.
659+
647660
.. method:: push_async_callback(callback, /, *args, **kwds)
648661

649662
Similar to :meth:`ExitStack.callback` but expects a coroutine function.

Doc/library/functions.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1824,19 +1824,19 @@ are always available. They are listed here in alphabetical order.
18241824
``range(start, stop, step)``. The *start* and *step* arguments default to
18251825
``None``.
18261826

1827-
Slice objects have read-only data attributes :attr:`!start`,
1828-
:attr:`!stop`, and :attr:`!step` which merely return the argument
1829-
values (or their default). They have no other explicit functionality;
1830-
however, they are used by NumPy and other third-party packages.
1827+
Slice objects are also generated when :ref:`slicing syntax <slicings>`
1828+
is used. For example: ``a[start:stop:step]`` or ``a[start:stop, i]``.
1829+
1830+
See :func:`itertools.islice` for an alternate version that returns an
1831+
:term:`iterator`.
18311832

18321833
.. attribute:: slice.start
1833-
.. attribute:: slice.stop
1834-
.. attribute:: slice.step
1834+
slice.stop
1835+
slice.step
18351836

1836-
Slice objects are also generated when extended indexing syntax is used. For
1837-
example: ``a[start:stop:step]`` or ``a[start:stop, i]``. See
1838-
:func:`itertools.islice` for an alternate version that returns an
1839-
:term:`iterator`.
1837+
These read-only attributes are set to the argument values
1838+
(or their default). They have no other explicit functionality;
1839+
however, they are used by NumPy and other third-party packages.
18401840

18411841
.. versionchanged:: 3.12
18421842
Slice objects are now :term:`hashable` (provided :attr:`~slice.start`,

Doc/library/stdtypes.rst

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2751,6 +2751,19 @@ expression support in the :mod:`re` module).
27512751
test string beginning at that position. With optional *end*, stop comparing
27522752
string at that position.
27532753

2754+
For example:
2755+
2756+
.. doctest::
2757+
2758+
>>> 'Python'.startswith('Py')
2759+
True
2760+
>>> 'a tuple of prefixes'.startswith(('at', 'a'))
2761+
True
2762+
>>> 'Python is amazing'.startswith('is', 7)
2763+
True
2764+
2765+
See also :meth:`endswith` and :meth:`removeprefix`.
2766+
27542767

27552768
.. method:: str.strip(chars=None, /)
27562769

Doc/library/urllib.robotparser.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,16 +91,16 @@ class::
9191

9292
>>> import urllib.robotparser
9393
>>> rp = urllib.robotparser.RobotFileParser()
94-
>>> rp.set_url("http://www.musi-cal.com/robots.txt")
94+
>>> rp.set_url("http://www.pythontest.net/robots.txt")
9595
>>> rp.read()
9696
>>> rrate = rp.request_rate("*")
9797
>>> rrate.requests
98-
3
98+
1
9999
>>> rrate.seconds
100-
20
100+
1
101101
>>> rp.crawl_delay("*")
102102
6
103-
>>> rp.can_fetch("*", "http://www.musi-cal.com/cgi-bin/search?city=San+Francisco")
104-
False
105-
>>> rp.can_fetch("*", "http://www.musi-cal.com/")
103+
>>> rp.can_fetch("*", "http://www.pythontest.net/")
106104
True
105+
>>> rp.can_fetch("*", "http://www.pythontest.net/no-robots-here/")
106+
False

Doc/license.rst

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1199,3 +1199,39 @@ The d3.js library contains the following notice::
11991199
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
12001200
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
12011201
THIS SOFTWARE.
1202+
1203+
1204+
Pixi packages
1205+
-------------
1206+
1207+
The Pixi package definitions found in :file:`Tools/pixi-packages` are derived
1208+
from https://github.com/conda-forge/python-feedstock which contains the following
1209+
license::
1210+
1211+
BSD-3-Clause license
1212+
Copyright (c) 2015-2026, conda-forge contributors
1213+
All rights reserved.
1214+
1215+
Redistribution and use in source and binary forms, with or without
1216+
modification, are permitted provided that the following conditions are met:
1217+
1218+
1. Redistributions of source code must retain the above copyright notice,
1219+
this list of conditions and the following disclaimer.
1220+
2. Redistributions in binary form must reproduce the above copyright
1221+
notice, this list of conditions and the following disclaimer in the
1222+
documentation and/or other materials provided with the distribution.
1223+
3. Neither the name of the copyright holder nor the names of its
1224+
contributors may be used to endorse or promote products derived from
1225+
this software without specific prior written permission.
1226+
1227+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
1228+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1229+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1230+
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
1231+
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
1232+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
1233+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
1234+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
1235+
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
1236+
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
1237+
DAMAGE.

0 commit comments

Comments
 (0)