Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
96 changes: 96 additions & 0 deletions Doc/c-api/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,35 @@ complete listing.

.. versionadded:: 3.3

.. c:macro:: Py_ALIGNED(num)

Specify alignment to *num* bytes on compilers that support it.

Consider using the C11 standard ``_Alignas`` specifier over this macro.

.. c:macro:: Py_ARITHMETIC_RIGHT_SHIFT(type, integer, positions)

Similar to ``integer >> positions``, but forces sign extension, as the C
standard does not define whether a right-shift of a signed integer will
perform sign extension or a zero-fill.

*integer* should be any signed integer type.
*positions* is the number of positions to shift to the right.

Both *integer* and *positions* can be evaluated more than once;
consequently, avoid directly passing a function call or some other
operation with side-effects to this macro. Instead, store the result as a
variable and then pass it.

*type* is unused and only kept for backwards compatibility. Historically,
*type* was used to cast *integer*.

.. versionchanged:: 3.1

This macro is now valid for all signed integer types, not just those for
which ``unsigned type`` is legal. As a result, *type* is no longer
used.

.. c:macro:: Py_ALWAYS_INLINE

Ask the compiler to always inline a static inline function. The compiler can
Expand All @@ -189,6 +218,15 @@ complete listing.

.. versionadded:: 3.11

.. c:macro:: Py_CAN_START_THREADS

If this macro is defined, then the current system is able to start threads.

Currently, all systems supported by CPython (per :pep:`11`), with the
exception of some WebAssembly platforms, support starting threads.

.. versionadded:: 3.13

.. c:macro:: Py_CHARMASK(c)

Argument must be a character or an integer in the range [-128, 127] or [0,
Expand All @@ -206,11 +244,35 @@ complete listing.
.. versionchanged:: 3.8
MSVC support was added.

.. c:macro:: Py_FORCE_EXPANSION(X)

This is equivalent to ``X``, which is useful for token-pasting in
macros, as macro expansions in *X* are forcefully evaluated by the
preprocessor.

.. c:macro:: Py_GCC_ATTRIBUTE(name)

Use a GCC attribute *name*, hiding it from compilers that don't support GCC
attributes (such as MSVC).

This expands to ``__attribute__((name))`` on a GCC compiler, and expands
to nothing on compilers that don't support GCC attributes.

.. c:macro:: Py_GETENV(s)

Like ``getenv(s)``, but returns ``NULL`` if :option:`-E` was passed on the
command line (see :c:member:`PyConfig.use_environment`).

.. c:macro:: Py_LL(number)

Use *number* as a ``long long`` integer literal.

This usally expands to *number* followed by ``LL``, but will expand to some
compiler-specific suffixes (such as ``I64``) on older compilers.

In modern versions of Python, this macro is not very useful, as C99 and
later require the ``LL`` suffix to be valid for an integer.

.. c:macro:: Py_LOCAL(type)

Declare a function returning the specified *type* using a fast-calling
Expand Down Expand Up @@ -268,13 +330,37 @@ complete listing.

.. versionadded:: 3.11

.. c:macro:: Py_SAFE_DOWNCAST(value, larger, smaller)

Cast *value* to type *smaller* from type *larger*, validating that no
information was lost.

On release builds of Python, this is roughly equivalent to
``(smaller) value`` (in C++, ``static_cast<smaller>(value)`` will be
used instead).

On debug builds (implying that :c:macro:`Py_DEBUG` is defined), this asserts
that no information was lost with the cast from *larger* to *smaller*.

*value*, *larger*, and *smaller* may all be evaluated more than once in the
expression; consequently, do not pass an expression with side-effects directly to
this macro.

.. c:macro:: Py_STRINGIFY(x)

Convert ``x`` to a C string. E.g. ``Py_STRINGIFY(123)`` returns
``"123"``.

.. versionadded:: 3.4

.. c:macro:: Py_ULL(number)

Similar to :c:macro:`Py_LL`, but *number* will be an ``unsigned long long``
literal instead. This is done by appending ``U`` to the result of ``Py_LL``.

In modern versions of Python, this macro is not very useful, as C99 and
later require the ``ULL``/``LLU`` suffixes to be valid for an integer.

.. c:macro:: Py_UNREACHABLE()

Use this when you have a code path that cannot be reached by design.
Expand Down Expand Up @@ -415,6 +501,16 @@ complete listing.
This macro is intended for defining CPython's C API itself;
extension modules should not use it for their own symbols.

.. c:macro:: Py_VA_COPY

This is a :term:`soft deprecated` alias to the C99-standard ``va_copy``
function.

Historically, this would use a compiler-specific method to copy a ``va_list``.

.. versionchanged:: 3.6
This is now an alias to ``va_copy``.


.. _api-objects:

Expand Down
33 changes: 29 additions & 4 deletions Doc/glossary.rst
Original file line number Diff line number Diff line change
Expand Up @@ -786,6 +786,19 @@ Glossary
An object that both finds and loads a module; both a
:term:`finder` and :term:`loader` object.

index
A numeric value that represents the position of an element in
a :term:`sequence`.

In Python, indexing starts at zero.
For example, ``things[0]`` names the *first* element of ``things``;
``things[1]`` names the second one.

In some contexts, Python allows negative indexes for counting from the
end of a sequence, and indexing using :term:`slices <slice>`.

See also :term:`subscript`.

interactive
Python has an interactive interpreter which means you can enter
statements and expressions at the interpreter prompt, immediately
Expand Down Expand Up @@ -863,6 +876,9 @@ Glossary
CPython does not guarantee :term:`thread-safe` behavior of iterator
operations.

key
A value that identifies an entry in a :term:`mapping`.
See also :term:`subscript`.

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

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

soft deprecated
A soft deprecated API should not be used in new code,
Expand Down Expand Up @@ -1478,6 +1495,14 @@ Glossary

See also :term:`borrowed reference`.

subscript
The expression in square brackets of a
:ref:`subscription expression <subscriptions>`, for example,
the ``3`` in ``items[3]``.
Usually used to select an element of a container.
Also called a :term:`key` when subscripting a :term:`mapping`,
or an :term:`index` when subscripting a :term:`sequence`.

synchronization primitive
A basic building block for coordinating (synchronizing) the execution of
multiple threads to ensure :term:`thread-safe` access to shared resources.
Expand Down
20 changes: 10 additions & 10 deletions Doc/library/functions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1824,19 +1824,19 @@ are always available. They are listed here in alphabetical order.
``range(start, stop, step)``. The *start* and *step* arguments default to
``None``.

Slice objects have read-only data attributes :attr:`!start`,
:attr:`!stop`, and :attr:`!step` which merely return the argument
values (or their default). They have no other explicit functionality;
however, they are used by NumPy and other third-party packages.
Slice objects are also generated when :ref:`slicing syntax <slicings>`
is used. For example: ``a[start:stop:step]`` or ``a[start:stop, i]``.

See :func:`itertools.islice` for an alternate version that returns an
:term:`iterator`.

.. attribute:: slice.start
.. attribute:: slice.stop
.. attribute:: slice.step
slice.stop
slice.step

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

.. versionchanged:: 3.12
Slice objects are now :term:`hashable` (provided :attr:`~slice.start`,
Expand Down
13 changes: 13 additions & 0 deletions Doc/library/stdtypes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2751,6 +2751,19 @@ expression support in the :mod:`re` module).
test string beginning at that position. With optional *end*, stop comparing
string at that position.

For example:

.. doctest::

>>> 'Python'.startswith('Py')
True
>>> 'a tuple of prefixes'.startswith(('at', 'a'))
True
>>> 'Python is amazing'.startswith('is', 7)
True

See also :meth:`endswith` and :meth:`removeprefix`.


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

Expand Down
36 changes: 36 additions & 0 deletions Doc/license.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1199,3 +1199,39 @@ The d3.js library contains the following notice::
OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
THIS SOFTWARE.


Pixi packages
-------------

The Pixi package definitions found in :file:`Tools/pixi-packages` are derived
from https://github.com/conda-forge/python-feedstock which contains the following
license::

BSD-3-Clause license
Copyright (c) 2015-2026, conda-forge contributors
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.
3. Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
DAMAGE.
Loading
Loading