Skip to content

Commit

Permalink
Merge branch 'main' into tests-rereredux
Browse files Browse the repository at this point in the history
  • Loading branch information
barneygale committed Mar 4, 2025
2 parents f0afaab + 3dd3675 commit 65aa5c3
Show file tree
Hide file tree
Showing 167 changed files with 4,918 additions and 3,149 deletions.
2 changes: 1 addition & 1 deletion Doc/c-api/arg.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
Parsing arguments and building values
=====================================

These functions are useful when creating your own extensions functions and
These functions are useful when creating your own extension functions and
methods. Additional information and examples are available in
:ref:`extending-index`.

Expand Down
10 changes: 10 additions & 0 deletions Doc/c-api/intro.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@ familiar with writing an extension before attempting to embed Python in a real
application.


Language version compatibility
==============================

Python's C API is compatible with C11 and C++11 versions of C and C++.

This is a lower limit: the C API does not require features from later
C/C++ versions.
You do *not* need to enable your compiler's "c11 mode".


Coding standards
================

Expand Down
5 changes: 5 additions & 0 deletions Doc/c-api/structures.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ under :ref:`reference counting <countingrefs>`.
See documentation of :c:type:`PyVarObject` above.


.. c:var:: PyTypeObject PyBaseObject_Type
The base class of all other objects, the same as :class:`object` in Python.


.. c:function:: int Py_Is(PyObject *x, PyObject *y)
Test if the *x* object is the *y* object, the same as ``x is y`` in Python.
Expand Down
166 changes: 120 additions & 46 deletions Doc/c-api/unicode.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ Unicode Type
These are the basic Unicode object types used for the Unicode implementation in
Python:

.. c:var:: PyTypeObject PyUnicode_Type
This instance of :c:type:`PyTypeObject` represents the Python Unicode type. It
is exposed to Python code as :py:class:`str`.


.. c:type:: Py_UCS4
Py_UCS2
Py_UCS1
Expand All @@ -42,19 +48,6 @@ Python:
.. versionadded:: 3.3


.. c:type:: Py_UNICODE
This is a typedef of :c:type:`wchar_t`, which is a 16-bit type or 32-bit type
depending on the platform.

.. versionchanged:: 3.3
In previous versions, this was a 16-bit type or a 32-bit type depending on
whether you selected a "narrow" or "wide" Unicode version of Python at
build time.

.. deprecated-removed:: 3.13 3.15


.. c:type:: PyASCIIObject
PyCompactUnicodeObject
PyUnicodeObject
Expand All @@ -66,12 +59,6 @@ Python:
.. versionadded:: 3.3


.. c:var:: PyTypeObject PyUnicode_Type
This instance of :c:type:`PyTypeObject` represents the Python Unicode type. It
is exposed to Python code as ``str``.


The following APIs are C macros and static inlined functions for fast checks and
access to internal read-only data of Unicode objects:

Expand All @@ -87,16 +74,6 @@ access to internal read-only data of Unicode objects:
subtype. This function always succeeds.
.. c:function:: int PyUnicode_READY(PyObject *unicode)
Returns ``0``. This API is kept only for backward compatibility.
.. versionadded:: 3.3
.. deprecated:: 3.10
This API does nothing since Python 3.12.
.. c:function:: Py_ssize_t PyUnicode_GET_LENGTH(PyObject *unicode)
Return the length of the Unicode string, in code points. *unicode* has to be a
Expand Down Expand Up @@ -149,12 +126,16 @@ access to internal read-only data of Unicode objects:
.. c:function:: void PyUnicode_WRITE(int kind, void *data, \
Py_ssize_t index, Py_UCS4 value)
Write into a canonical representation *data* (as obtained with
:c:func:`PyUnicode_DATA`). This function performs no sanity checks, and is
intended for usage in loops. The caller should cache the *kind* value and
*data* pointer as obtained from other calls. *index* is the index in
the string (starts at 0) and *value* is the new code point value which should
be written to that location.
Write the code point *value* to the given zero-based *index* in a string.
The *kind* value and *data* pointer must have been obtained from a
string using :c:func:`PyUnicode_KIND` and :c:func:`PyUnicode_DATA`
respectively. You must hold a reference to that string while calling
:c:func:`!PyUnicode_WRITE`. All requirements of
:c:func:`PyUnicode_WriteChar` also apply.
The function performs no checks for any of its requirements,
and is intended for usage in loops.
.. versionadded:: 3.3
Expand Down Expand Up @@ -196,6 +177,14 @@ access to internal read-only data of Unicode objects:
is not ready.
.. c:function:: unsigned int PyUnicode_IS_ASCII(PyObject *unicode)
Return true if the string only contains ASCII characters.
Equivalent to :py:meth:`str.isascii`.
.. versionadded:: 3.2
Unicode Character Properties
""""""""""""""""""""""""""""
Expand Down Expand Up @@ -330,11 +319,29 @@ APIs:
to be placed in the string. As an approximation, it can be rounded up to the
nearest value in the sequence 127, 255, 65535, 1114111.
This is the recommended way to allocate a new Unicode object. Objects
created using this function are not resizable.
On error, set an exception and return ``NULL``.
After creation, the string can be filled by :c:func:`PyUnicode_WriteChar`,
:c:func:`PyUnicode_CopyCharacters`, :c:func:`PyUnicode_Fill`,
:c:func:`PyUnicode_WRITE` or similar.
Since strings are supposed to be immutable, take care to not “use” the
result while it is being modified. In particular, before it's filled
with its final contents, a string:
- must not be hashed,
- must not be :c:func:`converted to UTF-8 <PyUnicode_AsUTF8AndSize>`,
or another non-"canonical" representation,
- must not have its reference count changed,
- must not be shared with code that might do one of the above.
This list is not exhaustive. Avoiding these uses is your responsibility;
Python does not always check these requirements.
To avoid accidentally exposing a partially-written string object, prefer
using the :c:type:`PyUnicodeWriter` API, or one of the ``PyUnicode_From*``
functions below.
.. versionadded:: 3.3
Expand Down Expand Up @@ -636,6 +643,9 @@ APIs:
possible. Returns ``-1`` and sets an exception on error, otherwise returns
the number of copied characters.
The string must not have been “used” yet.
See :c:func:`PyUnicode_New` for details.
.. versionadded:: 3.3
Expand All @@ -648,6 +658,9 @@ APIs:
Fail if *fill_char* is bigger than the string maximum character, or if the
string has more than 1 reference.
The string must not have been “used” yet.
See :c:func:`PyUnicode_New` for details.
Return the number of written character, or return ``-1`` and raise an
exception on error.
Expand All @@ -657,15 +670,16 @@ APIs:
.. c:function:: int PyUnicode_WriteChar(PyObject *unicode, Py_ssize_t index, \
Py_UCS4 character)
Write a character to a string. The string must have been created through
:c:func:`PyUnicode_New`. Since Unicode strings are supposed to be immutable,
the string must not be shared, or have been hashed yet.
Write a *character* to the string *unicode* at the zero-based *index*.
Return ``0`` on success, ``-1`` on error with an exception set.
This function checks that *unicode* is a Unicode object, that the index is
not out of bounds, and that the object can be modified safely (i.e. that it
its reference count is one).
not out of bounds, and that the object's reference count is one).
See :c:func:`PyUnicode_WRITE` for a version that skips these checks,
making them your responsibility.
Return ``0`` on success, ``-1`` on error with an exception set.
The string must not have been “used” yet.
See :c:func:`PyUnicode_New` for details.
.. versionadded:: 3.3
Expand Down Expand Up @@ -1649,6 +1663,20 @@ They all return ``NULL`` or ``-1`` if an exception occurs.
Strings interned this way are made :term:`immortal`.
.. c:function:: unsigned int PyUnicode_CHECK_INTERNED(PyObject *str)
Return a non-zero value if *str* is interned, zero if not.
The *str* argument must be a string; this is not checked.
This function always succeeds.
.. impl-detail::
A non-zero return value may carry additional information
about *how* the string is interned.
The meaning of such non-zero values, as well as each specific string's
intern-related details, may change between CPython versions.
PyUnicodeWriter
^^^^^^^^^^^^^^^
Expand Down Expand Up @@ -1769,8 +1797,8 @@ object.
*size* is the string length in bytes. If *size* is equal to ``-1``, call
``strlen(str)`` to get the string length.
*errors* is an error handler name, such as ``"replace"``. If *errors* is
``NULL``, use the strict error handler.
*errors* is an :ref:`error handler <error-handlers>` name, such as
``"replace"``. If *errors* is ``NULL``, use the strict error handler.
If *consumed* is not ``NULL``, set *\*consumed* to the number of decoded
bytes on success.
Expand All @@ -1781,3 +1809,49 @@ object.
On error, set an exception, leave the writer unchanged, and return ``-1``.
See also :c:func:`PyUnicodeWriter_WriteUTF8`.
Deprecated API
^^^^^^^^^^^^^^
The following API is deprecated.
.. c:type:: Py_UNICODE
This is a typedef of :c:type:`wchar_t`, which is a 16-bit type or 32-bit type
depending on the platform.
Please use :c:type:`wchar_t` directly instead.
.. versionchanged:: 3.3
In previous versions, this was a 16-bit type or a 32-bit type depending on
whether you selected a "narrow" or "wide" Unicode version of Python at
build time.
.. deprecated-removed:: 3.13 3.15
.. c:function:: int PyUnicode_READY(PyObject *unicode)
Do nothing and return ``0``.
This API is kept only for backward compatibility, but there are no plans
to remove it.
.. versionadded:: 3.3
.. deprecated:: 3.10
This API does nothing since Python 3.12.
Previously, this needed to be called for each string created using
the old API (:c:func:`!PyUnicode_FromUnicode` or similar).
.. c:function:: unsigned int PyUnicode_IS_READY(PyObject *unicode)
Do nothing and return ``1``.
This API is kept only for backward compatibility, but there are no plans
to remove it.
.. versionadded:: 3.3
.. deprecated:: next
This API does nothing since Python 3.12.
Previously, this could be called to check if
:c:func:`PyUnicode_READY` is necessary.
1 change: 1 addition & 0 deletions Doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
'glossary_search',
'grammar_snippet',
'implementation_detail',
'issue_role',
'lexers',
'misc_news',
'pydoc_topics',
Expand Down
21 changes: 11 additions & 10 deletions Doc/library/collections.rst
Original file line number Diff line number Diff line change
Expand Up @@ -748,8 +748,8 @@ stack manipulations such as ``dup``, ``drop``, ``swap``, ``over``, ``pick``,
returns or raises is then returned or raised by :meth:`~object.__getitem__`.

Note that :meth:`__missing__` is *not* called for any operations besides
:meth:`~object.__getitem__`. This means that :meth:`get` will, like normal
dictionaries, return ``None`` as a default rather than using
:meth:`~object.__getitem__`. This means that :meth:`~dict.get` will, like
normal dictionaries, return ``None`` as a default rather than using
:attr:`default_factory`.


Expand Down Expand Up @@ -849,8 +849,9 @@ they add the ability to access fields by name instead of position index.
Returns a new tuple subclass named *typename*. The new subclass is used to
create tuple-like objects that have fields accessible by attribute lookup as
well as being indexable and iterable. Instances of the subclass also have a
helpful docstring (with typename and field_names) and a helpful :meth:`__repr__`
method which lists the tuple contents in a ``name=value`` format.
helpful docstring (with *typename* and *field_names*) and a helpful
:meth:`~object.__repr__` method which lists the tuple contents in a ``name=value``
format.

The *field_names* are a sequence of strings such as ``['x', 'y']``.
Alternatively, *field_names* can be a single string with each fieldname
Expand Down Expand Up @@ -894,10 +895,10 @@ they add the ability to access fields by name instead of position index.
Added the *module* parameter.

.. versionchanged:: 3.7
Removed the *verbose* parameter and the :attr:`_source` attribute.
Removed the *verbose* parameter and the :attr:`!_source` attribute.

.. versionchanged:: 3.7
Added the *defaults* parameter and the :attr:`_field_defaults`
Added the *defaults* parameter and the :attr:`~somenamedtuple._field_defaults`
attribute.

.. doctest::
Expand Down Expand Up @@ -1109,7 +1110,7 @@ Some differences from :class:`dict` still remain:
A regular :class:`dict` can emulate the order sensitive equality test with
``p == q and all(k1 == k2 for k1, k2 in zip(p, q))``.

* The :meth:`popitem` method of :class:`OrderedDict` has a different
* The :meth:`~OrderedDict.popitem` method of :class:`OrderedDict` has a different
signature. It accepts an optional argument to specify which item is popped.

A regular :class:`dict` can emulate OrderedDict's ``od.popitem(last=True)``
Expand All @@ -1119,7 +1120,7 @@ Some differences from :class:`dict` still remain:
with ``(k := next(iter(d)), d.pop(k))`` which will return and remove the
leftmost (first) item if it exists.

* :class:`OrderedDict` has a :meth:`move_to_end` method to efficiently
* :class:`OrderedDict` has a :meth:`~OrderedDict.move_to_end` method to efficiently
reposition an element to an endpoint.

A regular :class:`dict` can emulate OrderedDict's ``od.move_to_end(k,
Expand All @@ -1130,7 +1131,7 @@ Some differences from :class:`dict` still remain:
OrderedDict's ``od.move_to_end(k, last=False)`` which moves the key
and its associated value to the leftmost (first) position.

* Until Python 3.8, :class:`dict` lacked a :meth:`__reversed__` method.
* Until Python 3.8, :class:`dict` lacked a :meth:`~object.__reversed__` method.


.. class:: OrderedDict([items])
Expand Down Expand Up @@ -1185,7 +1186,7 @@ anywhere a regular dictionary is used.

.. versionchanged:: 3.6
With the acceptance of :pep:`468`, order is retained for keyword arguments
passed to the :class:`OrderedDict` constructor and its :meth:`update`
passed to the :class:`OrderedDict` constructor and its :meth:`~dict.update`
method.

.. versionchanged:: 3.9
Expand Down
9 changes: 5 additions & 4 deletions Doc/library/constants.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,12 @@ A small number of constants live in the built-in namespace. They are:

See :ref:`implementing-the-arithmetic-operations` for examples.

.. note::
.. caution::

``NotImplementedError`` and :data:`!NotImplemented` are not interchangeable,
even though they have similar names and purposes.
See :exc:`NotImplementedError` for details on when to use it.
:data:`!NotImplemented` and :exc:`!NotImplementedError` are not
interchangeable. This constant should only be used as described
above; see :exc:`NotImplementedError` for details on correct usage
of the exception.

.. versionchanged:: 3.9
Evaluating :data:`!NotImplemented` in a boolean context was deprecated.
Expand Down
Loading

0 comments on commit 65aa5c3

Please sign in to comment.