Skip to content

Commit 016eb6d

Browse files
committed
Merge branch 'main' into gh-128446
2 parents 6d37f98 + 8d15058 commit 016eb6d

Some content is hidden

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

53 files changed

+1889
-686
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

.pre-commit-config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ repos:
5555
hooks:
5656
- id: check-dependabot
5757
- id: check-github-workflows
58+
- id: check-readthedocs
5859

5960
- repo: https://github.com/rhysd/actionlint
6061
rev: v1.7.4

Doc/c-api/arg.rst

Lines changed: 14 additions & 8 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]
@@ -344,12 +356,6 @@ Other objects
344356
in *items*. The C arguments must correspond to the individual format units in
345357
*items*. Format units for sequences may be nested.
346358

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-
353359
A few other characters have a meaning in a format string. These may not occur
354360
inside nested parentheses. They are:
355361

Doc/c-api/object.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -493,6 +493,13 @@ Object Protocol
493493
on failure. This is equivalent to the Python statement ``del o[key]``.
494494
495495
496+
.. c:function:: int PyObject_DelItemString(PyObject *o, const char *key)
497+
498+
This is the same as :c:func:`PyObject_DelItem`, but *key* is
499+
specified as a :c:expr:`const char*` UTF-8 encoded bytes string,
500+
rather than a :c:expr:`PyObject*`.
501+
502+
496503
.. c:function:: PyObject* PyObject_Dir(PyObject *o)
497504
498505
This is equivalent to the Python expression ``dir(o)``, returning a (possibly

Doc/library/ctypes.rst

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2182,6 +2182,28 @@ Utility functions
21822182
.. audit-event:: ctypes.wstring_at ptr,size ctypes.wstring_at
21832183

21842184

2185+
.. function:: memoryview_at(ptr, size, readonly=False)
2186+
2187+
Return a :class:`memoryview` object of length *size* that references memory
2188+
starting at *void \*ptr*.
2189+
2190+
If *readonly* is true, the returned :class:`!memoryview` object can
2191+
not be used to modify the underlying memory.
2192+
(Changes made by other means will still be reflected in the returned
2193+
object.)
2194+
2195+
This function is similar to :func:`string_at` with the key
2196+
difference of not making a copy of the specified memory.
2197+
It is a semantically equivalent (but more efficient) alternative to
2198+
``memoryview((c_byte * size).from_address(ptr))``.
2199+
(While :meth:`~_CData.from_address` only takes integers, *ptr* can also
2200+
be given as a :class:`ctypes.POINTER` or a :func:`~ctypes.byref` object.)
2201+
2202+
.. audit-event:: ctypes.memoryview_at address,size,readonly
2203+
2204+
.. versionadded:: next
2205+
2206+
21852207
.. _ctypes-data-types:
21862208

21872209
Data types

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/faulthandler.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,10 @@ Fault handler state
9191
The dump now mentions if a garbage collector collection is running
9292
if *all_threads* is true.
9393

94+
.. versionchanged:: next
95+
Only the current thread is dumped if the :term:`GIL` is disabled to
96+
prevent the risk of data races.
97+
9498
.. function:: disable()
9599

96100
Disable the fault handler: uninstall the signal handlers installed by

Doc/library/json.rst

Lines changed: 74 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -151,69 +151,94 @@ Basic Usage
151151
sort_keys=False, **kw)
152152
153153
Serialize *obj* as a JSON formatted stream to *fp* (a ``.write()``-supporting
154-
:term:`file-like object`) using this :ref:`conversion table
154+
:term:`file-like object`) using this :ref:`Python-to-JSON conversion table
155155
<py-to-json-table>`.
156156

157-
If *skipkeys* is true (default: ``False``), then dict keys that are not
158-
of a basic type (:class:`str`, :class:`int`, :class:`float`, :class:`bool`,
159-
``None``) will be skipped instead of raising a :exc:`TypeError`.
160-
161-
The :mod:`json` module always produces :class:`str` objects, not
162-
:class:`bytes` objects. Therefore, ``fp.write()`` must support :class:`str`
163-
input.
164-
165-
If *ensure_ascii* is true (the default), the output is guaranteed to
166-
have all incoming non-ASCII characters escaped. If *ensure_ascii* is
167-
false, these characters will be output as-is.
168-
169-
If *check_circular* is false (default: ``True``), then the circular
170-
reference check for container types will be skipped and a circular reference
171-
will result in a :exc:`RecursionError` (or worse).
157+
.. note::
172158

173-
If *allow_nan* is false (default: ``True``), then it will be a
174-
:exc:`ValueError` to serialize out of range :class:`float` values (``nan``,
175-
``inf``, ``-inf``) in strict compliance of the JSON specification.
176-
If *allow_nan* is true, their JavaScript equivalents (``NaN``,
177-
``Infinity``, ``-Infinity``) will be used.
159+
Unlike :mod:`pickle` and :mod:`marshal`, JSON is not a framed protocol,
160+
so trying to serialize multiple objects with repeated calls to
161+
:func:`dump` using the same *fp* will result in an invalid JSON file.
178162

179-
If *indent* is a non-negative integer or string, then JSON array elements and
180-
object members will be pretty-printed with that indent level. An indent level
181-
of 0, negative, or ``""`` will only insert newlines. ``None`` (the default)
182-
selects the most compact representation. Using a positive integer indent
183-
indents that many spaces per level. If *indent* is a string (such as ``"\t"``),
184-
that string is used to indent each level.
163+
:param object obj:
164+
The Python object to be serialized.
165+
166+
:param fp:
167+
The file-like object *obj* will be serialized to.
168+
The :mod:`!json` module always produces :class:`str` objects,
169+
not :class:`bytes` objects,
170+
therefore ``fp.write()`` must support :class:`str` input.
171+
:type fp: :term:`file-like object`
172+
173+
:param bool skipkeys:
174+
If ``True``, keys that are not of a basic type
175+
(:class:`str`, :class:`int`, :class:`float`, :class:`bool`, ``None``)
176+
will be skipped instead of raising a :exc:`TypeError`.
177+
Default ``False``.
178+
179+
:param bool ensure_ascii:
180+
If ``True`` (the default), the output is guaranteed to
181+
have all incoming non-ASCII characters escaped.
182+
If ``False``, these characters will be outputted as-is.
183+
184+
:param bool check_circular:
185+
If ``False``, the circular reference check for container types is skipped
186+
and a circular reference will result in a :exc:`RecursionError` (or worse).
187+
Default ``True``.
188+
189+
:param bool allow_nan:
190+
If ``False``, serialization of out-of-range :class:`float` values
191+
(``nan``, ``inf``, ``-inf``) will result in a :exc:`ValueError`,
192+
in strict compliance with the JSON specification.
193+
If ``True`` (the default), their JavaScript equivalents
194+
(``NaN``, ``Infinity``, ``-Infinity``) are used.
195+
196+
:param cls:
197+
If set, a custom JSON encoder with the
198+
:meth:`~JSONEncoder.default` method overridden,
199+
for serializing into custom datatypes.
200+
If ``None`` (the default), :class:`!JSONEncoder` is used.
201+
:type cls: a :class:`JSONEncoder` subclass
202+
203+
:param indent:
204+
If a positive integer or string, JSON array elements and
205+
object members will be pretty-printed with that indent level.
206+
A positive integer indents that many spaces per level;
207+
a string (such as ``"\t"``) is used to indent each level.
208+
If zero, negative, or ``""`` (the empty string),
209+
only newlines are inserted.
210+
If ``None`` (the default), the most compact representation is used.
211+
:type indent: int | str | None
212+
213+
:param separators:
214+
A two-tuple: ``(item_separator, key_separator)``.
215+
If ``None`` (the default), *separators* defaults to
216+
``(', ', ': ')`` if *indent* is ``None``,
217+
and ``(',', ': ')`` otherwise.
218+
For the most compact JSON,
219+
specify ``(',', ':')`` to eliminate whitespace.
220+
:type separators: tuple | None
221+
222+
:param default:
223+
A function that is called for objects that can't otherwise be serialized.
224+
It should return a JSON encodable version of the object
225+
or raise a :exc:`TypeError`.
226+
If ``None`` (the default), :exc:`!TypeError` is raised.
227+
:type default: :term:`callable` | None
228+
229+
:param bool sort_keys:
230+
If ``True``, dictionaries will be outputted sorted by key.
231+
Default ``False``.
185232

186233
.. versionchanged:: 3.2
187234
Allow strings for *indent* in addition to integers.
188235

189-
If specified, *separators* should be an ``(item_separator, key_separator)``
190-
tuple. The default is ``(', ', ': ')`` if *indent* is ``None`` and
191-
``(',', ': ')`` otherwise. To get the most compact JSON representation,
192-
you should specify ``(',', ':')`` to eliminate whitespace.
193-
194236
.. versionchanged:: 3.4
195237
Use ``(',', ': ')`` as default if *indent* is not ``None``.
196238

197-
If specified, *default* should be a function that gets called for objects that
198-
can't otherwise be serialized. It should return a JSON encodable version of
199-
the object or raise a :exc:`TypeError`. If not specified, :exc:`TypeError`
200-
is raised.
201-
202-
If *sort_keys* is true (default: ``False``), then the output of
203-
dictionaries will be sorted by key.
204-
205-
To use a custom :class:`JSONEncoder` subclass (e.g. one that overrides the
206-
:meth:`~JSONEncoder.default` method to serialize additional types), specify it with the
207-
*cls* kwarg; otherwise :class:`JSONEncoder` is used.
208-
209239
.. versionchanged:: 3.6
210240
All optional parameters are now :ref:`keyword-only <keyword-only_parameter>`.
211241

212-
.. note::
213-
214-
Unlike :mod:`pickle` and :mod:`marshal`, JSON is not a framed protocol,
215-
so trying to serialize multiple objects with repeated calls to
216-
:func:`dump` using the same *fp* will result in an invalid JSON file.
217242

218243
.. function:: dumps(obj, *, skipkeys=False, ensure_ascii=True, \
219244
check_circular=True, allow_nan=True, cls=None, \

Doc/library/math.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ Floating point arithmetic
248248

249249
.. function:: fmod(x, y)
250250

251-
Return ``fmod(x, y)``, as defined by the platform C library. Note that the
251+
Return the floating-point remainder of ``x / y``,
252+
as defined by the platform C library function ``fmod(x, y)``. Note that the
252253
Python expression ``x % y`` may not return the same result. The intent of the C
253254
standard is that ``fmod(x, y)`` be exactly (mathematically; to infinite
254255
precision) equal to ``x - n*y`` for some integer *n* such that the result has

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

0 commit comments

Comments
 (0)