Skip to content

Commit 8d86513

Browse files
authored
Merge branch 'main' into remove-requires-working-socket-from-some-of-test-asyncgen
2 parents c2d2610 + 07e6aa2 commit 8d86513

File tree

91 files changed

+1887
-839
lines changed

Some content is hidden

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

91 files changed

+1887
-839
lines changed

.github/workflows/reusable-docs.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ jobs:
9999
# Run "doctest" on HEAD as new syntax doesn't exist in the latest stable release
100100
doctest:
101101
name: 'Doctest'
102-
runs-on: ubuntu-22.04
102+
runs-on: ubuntu-24.04
103103
timeout-minutes: 60
104104
steps:
105105
- uses: actions/checkout@v4

Doc/c-api/arg.rst

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -229,12 +229,24 @@ There are three ways strings and buffers can be converted to C:
229229
Numbers
230230
-------
231231

232+
These formats allow representing Python numbers or single characters as C numbers.
233+
Formats that require :class:`int`, :class:`float` or :class:`complex` can
234+
also use the corresponding special methods :meth:`~object.__index__`,
235+
:meth:`~object.__float__` or :meth:`~object.__complex__` to convert
236+
the Python object to the required type.
237+
238+
For signed integer formats, :exc:`OverflowError` is raised if the value
239+
is out of range for the C type.
240+
For unsigned integer formats, no range checking is done --- the
241+
most significant bits are silently truncated when the receiving field is too
242+
small to receive the value.
243+
232244
``b`` (:class:`int`) [unsigned char]
233-
Convert a nonnegative Python integer to an unsigned tiny int, stored in a C
245+
Convert a nonnegative Python integer to an unsigned tiny integer, stored in a C
234246
:c:expr:`unsigned char`.
235247

236248
``B`` (:class:`int`) [unsigned char]
237-
Convert a Python integer to a tiny int without overflow checking, stored in a C
249+
Convert a Python integer to a tiny integer without overflow checking, stored in a C
238250
:c:expr:`unsigned char`.
239251

240252
``h`` (:class:`int`) [short int]
@@ -307,7 +319,7 @@ Other objects
307319

308320
.. _o_ampersand:
309321

310-
``O&`` (object) [*converter*, *anything*]
322+
``O&`` (object) [*converter*, *address*]
311323
Convert a Python object to a C variable through a *converter* function. This
312324
takes two arguments: the first is a function, the second is the address of a C
313325
variable (of arbitrary type), converted to :c:expr:`void *`. The *converter*
@@ -321,14 +333,20 @@ Other objects
321333
the conversion has failed. When the conversion fails, the *converter* function
322334
should raise an exception and leave the content of *address* unmodified.
323335

324-
If the *converter* returns ``Py_CLEANUP_SUPPORTED``, it may get called a
336+
.. c:macro:: Py_CLEANUP_SUPPORTED
337+
:no-typesetting:
338+
339+
If the *converter* returns :c:macro:`!Py_CLEANUP_SUPPORTED`, it may get called a
325340
second time if the argument parsing eventually fails, giving the converter a
326341
chance to release any memory that it had already allocated. In this second
327342
call, the *object* parameter will be ``NULL``; *address* will have the same value
328343
as in the original call.
329344

345+
Examples of converters: :c:func:`PyUnicode_FSConverter` and
346+
:c:func:`PyUnicode_FSDecoder`.
347+
330348
.. versionchanged:: 3.1
331-
``Py_CLEANUP_SUPPORTED`` was added.
349+
:c:macro:`!Py_CLEANUP_SUPPORTED` was added.
332350

333351
``p`` (:class:`bool`) [int]
334352
Tests the value passed in for truth (a boolean **p**\ redicate) and converts
@@ -344,12 +362,6 @@ Other objects
344362
in *items*. The C arguments must correspond to the individual format units in
345363
*items*. Format units for sequences may be nested.
346364

347-
It is possible to pass "long" integers (integers whose value exceeds the
348-
platform's :c:macro:`LONG_MAX`) however no proper range checking is done --- the
349-
most significant bits are silently truncated when the receiving field is too
350-
small to receive the value (actually, the semantics are inherited from downcasts
351-
in C --- your mileage may vary).
352-
353365
A few other characters have a meaning in a format string. These may not occur
354366
inside nested parentheses. They are:
355367

Doc/c-api/sys.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,38 @@ Operating System Utilities
216216
The function now uses the UTF-8 encoding on Windows if
217217
:c:member:`PyPreConfig.legacy_windows_fs_encoding` is zero.
218218
219+
.. c:function:: FILE* Py_fopen(PyObject *path, const char *mode)
220+
221+
Similar to :c:func:`!fopen`, but *path* is a Python object and
222+
an exception is set on error.
223+
224+
*path* must be a :class:`str` object, a :class:`bytes` object,
225+
or a :term:`path-like object`.
226+
227+
On success, return the new file pointer.
228+
On error, set an exception and return ``NULL``.
229+
230+
The file must be closed by :c:func:`Py_fclose` rather than calling directly
231+
:c:func:`!fclose`.
232+
233+
The file descriptor is created non-inheritable (:pep:`446`).
234+
235+
The caller must hold the GIL.
236+
237+
.. versionadded:: next
238+
239+
240+
.. c:function:: int Py_fclose(FILE *file)
241+
242+
Close a file that was opened by :c:func:`Py_fopen`.
243+
244+
On success, return ``0``.
245+
On error, return ``EOF`` and ``errno`` is set to indicate the error.
246+
In either case, any further access (including another call to
247+
:c:func:`Py_fclose`) to the stream results in undefined behavior.
248+
249+
.. versionadded:: next
250+
219251
220252
.. _systemfunctions:
221253

Doc/c-api/unicode.rst

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -786,33 +786,52 @@ Functions encoding to and decoding from the :term:`filesystem encoding and
786786
error handler` (:pep:`383` and :pep:`529`).
787787
788788
To encode file names to :class:`bytes` during argument parsing, the ``"O&"``
789-
converter should be used, passing :c:func:`PyUnicode_FSConverter` as the
789+
converter should be used, passing :c:func:`!PyUnicode_FSConverter` as the
790790
conversion function:
791791
792792
.. c:function:: int PyUnicode_FSConverter(PyObject* obj, void* result)
793793
794-
ParseTuple converter: encode :class:`str` objects -- obtained directly or
794+
:ref:`PyArg_Parse\* converter <arg-parsing>`: encode :class:`str` objects -- obtained directly or
795795
through the :class:`os.PathLike` interface -- to :class:`bytes` using
796796
:c:func:`PyUnicode_EncodeFSDefault`; :class:`bytes` objects are output as-is.
797-
*result* must be a :c:expr:`PyBytesObject*` which must be released when it is
798-
no longer used.
797+
*result* must be an address of a C variable of type :c:expr:`PyObject*`
798+
(or :c:expr:`PyBytesObject*`).
799+
On success, set the variable to a new :term:`strong reference` to
800+
a :ref:`bytes object <bytesobjects>` which must be released
801+
when it is no longer used and return a non-zero value
802+
(:c:macro:`Py_CLEANUP_SUPPORTED`).
803+
Embedded null bytes are not allowed in the result.
804+
On failure, return ``0`` with an exception set.
805+
806+
If *obj* is ``NULL``, the function releases a strong reference
807+
stored in the variable referred by *result* and returns ``1``.
799808
800809
.. versionadded:: 3.1
801810
802811
.. versionchanged:: 3.6
803812
Accepts a :term:`path-like object`.
804813
805814
To decode file names to :class:`str` during argument parsing, the ``"O&"``
806-
converter should be used, passing :c:func:`PyUnicode_FSDecoder` as the
815+
converter should be used, passing :c:func:`!PyUnicode_FSDecoder` as the
807816
conversion function:
808817
809818
.. c:function:: int PyUnicode_FSDecoder(PyObject* obj, void* result)
810819
811-
ParseTuple converter: decode :class:`bytes` objects -- obtained either
820+
:ref:`PyArg_Parse\* converter <arg-parsing>`: decode :class:`bytes` objects -- obtained either
812821
directly or indirectly through the :class:`os.PathLike` interface -- to
813822
:class:`str` using :c:func:`PyUnicode_DecodeFSDefaultAndSize`; :class:`str`
814-
objects are output as-is. *result* must be a :c:expr:`PyUnicodeObject*` which
815-
must be released when it is no longer used.
823+
objects are output as-is.
824+
*result* must be an address of a C variable of type :c:expr:`PyObject*`
825+
(or :c:expr:`PyUnicodeObject*`).
826+
On success, set the variable to a new :term:`strong reference` to
827+
a :ref:`Unicode object <unicodeobjects>` which must be released
828+
when it is no longer used and return a non-zero value
829+
(:c:macro:`Py_CLEANUP_SUPPORTED`).
830+
Embedded null characters are not allowed in the result.
831+
On failure, return ``0`` with an exception set.
832+
833+
If *obj* is ``NULL``, release the strong reference
834+
to the object referred to by *result* and return ``1``.
816835
817836
.. versionadded:: 3.2
818837

Doc/library/calendar.rst

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,13 +38,33 @@ interpreted as prescribed by the ISO 8601 standard. Year 0 is 1 BC, year -1 is
3838
itself. This is the job of subclasses.
3939

4040

41-
:class:`Calendar` instances have the following methods:
41+
:class:`Calendar` instances have the following methods and attributes:
42+
43+
.. attribute:: firstweekday
44+
45+
The first weekday as an integer (0--6).
46+
47+
This property can also be set and read using
48+
:meth:`~Calendar.setfirstweekday` and
49+
:meth:`~Calendar.getfirstweekday` respectively.
50+
51+
.. method:: getfirstweekday()
52+
53+
Return an :class:`int` for the current first weekday (0--6).
54+
55+
Identical to reading the :attr:`~Calendar.firstweekday` property.
56+
57+
.. method:: setfirstweekday(firstweekday)
58+
59+
Set the first weekday to *firstweekday*, passed as an :class:`int` (0--6)
60+
61+
Identical to setting the :attr:`~Calendar.firstweekday` property.
4262

4363
.. method:: iterweekdays()
4464

4565
Return an iterator for the week day numbers that will be used for one
4666
week. The first value from the iterator will be the same as the value of
47-
the :attr:`firstweekday` property.
67+
the :attr:`~Calendar.firstweekday` property.
4868

4969

5070
.. method:: itermonthdates(year, month)

Doc/library/ctypes.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1812,6 +1812,8 @@ different ways, depending on the type and number of the parameters in the call:
18121812
the COM interface as first argument, in addition to those parameters that
18131813
are specified in the :attr:`!argtypes` tuple.
18141814

1815+
.. availability:: Windows
1816+
18151817

18161818
The optional *paramflags* parameter creates foreign function wrappers with much
18171819
more functionality than the features described above.

Doc/library/email.policy.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ added matters. To illustrate::
267267

268268
Handle a *defect* found on *obj*. When the email package calls this
269269
method, *defect* will always be a subclass of
270-
:class:`~email.errors.Defect`.
270+
:class:`~email.errors.MessageDefect`.
271271

272272
The default implementation checks the :attr:`raise_on_defect` flag. If
273273
it is ``True``, *defect* is raised as an exception. If it is ``False``
@@ -277,7 +277,7 @@ added matters. To illustrate::
277277
.. method:: register_defect(obj, defect)
278278

279279
Register a *defect* on *obj*. In the email package, *defect* will always
280-
be a subclass of :class:`~email.errors.Defect`.
280+
be a subclass of :class:`~email.errors.MessageDefect`.
281281

282282
The default implementation calls the ``append`` method of the ``defects``
283283
attribute of *obj*. When the email package calls :attr:`handle_defect`,

Doc/library/json.rst

Lines changed: 69 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -258,64 +258,89 @@ Basic Usage
258258
the original one. That is, ``loads(dumps(x)) != x`` if x has non-string
259259
keys.
260260

261-
.. function:: load(fp, *, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw)
261+
.. function:: load(fp, *, cls=None, object_hook=None, parse_float=None, \
262+
parse_int=None, parse_constant=None, \
263+
object_pairs_hook=None, **kw)
262264
263-
Deserialize *fp* (a ``.read()``-supporting :term:`text file` or
264-
:term:`binary file` containing a JSON document) to a Python object using
265-
this :ref:`conversion table <json-to-py-table>`.
265+
Deserialize *fp* to a Python object
266+
using the :ref:`JSON-to-Python conversion table <json-to-py-table>`.
266267

267-
*object_hook* is an optional function that will be called with the result of
268-
any object literal decoded (a :class:`dict`). The return value of
269-
*object_hook* will be used instead of the :class:`dict`. This feature can
270-
be used to implement custom decoders (e.g. `JSON-RPC
271-
<https://www.jsonrpc.org>`_ class hinting).
268+
:param fp:
269+
A ``.read()``-supporting :term:`text file` or :term:`binary file`
270+
containing the JSON document to be deserialized.
271+
:type fp: :term:`file-like object`
272272

273-
*object_pairs_hook* is an optional function that will be called with the
274-
result of any object literal decoded with an ordered list of pairs. The
275-
return value of *object_pairs_hook* will be used instead of the
276-
:class:`dict`. This feature can be used to implement custom decoders. If
277-
*object_hook* is also defined, the *object_pairs_hook* takes priority.
273+
:param cls:
274+
If set, a custom JSON decoder.
275+
Additional keyword arguments to :func:`!load`
276+
will be passed to the constructor of *cls*.
277+
If ``None`` (the default), :class:`!JSONDecoder` is used.
278+
:type cls: a :class:`JSONDecoder` subclass
279+
280+
:param object_hook:
281+
If set, a function that is called with the result of
282+
any object literal decoded (a :class:`dict`).
283+
The return value of this function will be used
284+
instead of the :class:`dict`.
285+
This feature can be used to implement custom decoders,
286+
for example `JSON-RPC <https://www.jsonrpc.org>`_ class hinting.
287+
Default ``None``.
288+
:type object_hook: :term:`callable` | None
289+
290+
:param object_pairs_hook:
291+
If set, a function that is called with the result of
292+
any object literal decoded with an ordered list of pairs.
293+
The return value of this function will be used
294+
instead of the :class:`dict`.
295+
This feature can be used to implement custom decoders.
296+
If *object_hook* is also set, *object_pairs_hook* takes priority.
297+
Default ``None``.
298+
:type object_pairs_hook: :term:`callable` | None
299+
300+
:param parse_float:
301+
If set, a function that is called with
302+
the string of every JSON float to be decoded.
303+
If ``None`` (the default), it is equivalent to ``float(num_str)``.
304+
This can be used to parse JSON floats into custom datatypes,
305+
for example :class:`decimal.Decimal`.
306+
:type parse_float: :term:`callable` | None
307+
308+
:param parse_int:
309+
If set, a function that is called with
310+
the string of every JSON int to be decoded.
311+
If ``None`` (the default), it is equivalent to ``int(num_str)``.
312+
This can be used to parse JSON integers into custom datatypes,
313+
for example :class:`float`.
314+
:type parse_int: :term:`callable` | None
315+
316+
:param parse_constant:
317+
If set, a function that is called with one of the following strings:
318+
``'-Infinity'``, ``'Infinity'``, or ``'NaN'``.
319+
This can be used to raise an exception
320+
if invalid JSON numbers are encountered.
321+
Default ``None``.
322+
:type parse_constant: :term:`callable` | None
323+
324+
:raises JSONDecodeError:
325+
When the data being deserialized is not a valid JSON document.
278326

279327
.. versionchanged:: 3.1
280-
Added support for *object_pairs_hook*.
281328

282-
*parse_float* is an optional function that will be called with the string of
283-
every JSON float to be decoded. By default, this is equivalent to
284-
``float(num_str)``. This can be used to use another datatype or parser for
285-
JSON floats (e.g. :class:`decimal.Decimal`).
329+
* Added the optional *object_pairs_hook* parameter.
330+
* *parse_constant* doesn't get called on 'null', 'true', 'false' anymore.
286331

287-
*parse_int* is an optional function that will be called with the string of
288-
every JSON int to be decoded. By default, this is equivalent to
289-
``int(num_str)``. This can be used to use another datatype or parser for
290-
JSON integers (e.g. :class:`float`).
332+
.. versionchanged:: 3.6
333+
334+
* All optional parameters are now :ref:`keyword-only <keyword-only_parameter>`.
335+
* *fp* can now be a :term:`binary file`.
336+
The input encoding should be UTF-8, UTF-16 or UTF-32.
291337

292338
.. versionchanged:: 3.11
293339
The default *parse_int* of :func:`int` now limits the maximum length of
294340
the integer string via the interpreter's :ref:`integer string
295341
conversion length limitation <int_max_str_digits>` to help avoid denial
296342
of service attacks.
297343

298-
*parse_constant* is an optional function that will be called with one of the
299-
following strings: ``'-Infinity'``, ``'Infinity'``, ``'NaN'``. This can be
300-
used to raise an exception if invalid JSON numbers are encountered.
301-
302-
.. versionchanged:: 3.1
303-
*parse_constant* doesn't get called on 'null', 'true', 'false' anymore.
304-
305-
To use a custom :class:`JSONDecoder` subclass, specify it with the ``cls``
306-
kwarg; otherwise :class:`JSONDecoder` is used. Additional keyword arguments
307-
will be passed to the constructor of the class.
308-
309-
If the data being deserialized is not a valid JSON document, a
310-
:exc:`JSONDecodeError` will be raised.
311-
312-
.. versionchanged:: 3.6
313-
All optional parameters are now :ref:`keyword-only <keyword-only_parameter>`.
314-
315-
.. versionchanged:: 3.6
316-
*fp* can now be a :term:`binary file`. The input encoding should be
317-
UTF-8, UTF-16 or UTF-32.
318-
319344
.. function:: loads(s, *, cls=None, object_hook=None, parse_float=None, parse_int=None, parse_constant=None, object_pairs_hook=None, **kw)
320345

321346
Deserialize *s* (a :class:`str`, :class:`bytes` or :class:`bytearray`

Doc/tools/.nitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ Doc/library/email.charset.rst
2323
Doc/library/email.compat32-message.rst
2424
Doc/library/email.errors.rst
2525
Doc/library/email.parser.rst
26-
Doc/library/email.policy.rst
2726
Doc/library/exceptions.rst
2827
Doc/library/functools.rst
2928
Doc/library/http.cookiejar.rst

Doc/whatsnew/3.14.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1237,6 +1237,12 @@ New features
12371237
:monitoring-event:`BRANCH_LEFT` and :monitoring-event:`BRANCH_RIGHT`
12381238
events, respectively.
12391239

1240+
* Add :c:func:`Py_fopen` function to open a file. Similar to the
1241+
:c:func:`!fopen` function, but the *path* parameter is a Python object and an
1242+
exception is set on error. Add also :c:func:`Py_fclose` function to close a
1243+
file.
1244+
(Contributed by Victor Stinner in :gh:`127350`.)
1245+
12401246

12411247
Porting to Python 3.14
12421248
----------------------

0 commit comments

Comments
 (0)