Skip to content

Commit c2d2610

Browse files
authored
Merge branch 'main' into remove-requires-working-socket-from-some-of-test-asyncgen
2 parents a80de9c + ae23a01 commit c2d2610

File tree

21 files changed

+1312
-435
lines changed

21 files changed

+1312
-435
lines changed

.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/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/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/using/configure.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Features and minimum versions required to build CPython:
2929

3030
* Tcl/Tk 8.5.12 for the :mod:`tkinter` module.
3131

32-
* Autoconf 2.71 and aclocal 1.16.5 are required to regenerate the
32+
* Autoconf 2.72 and aclocal 1.16.5 are required to regenerate the
3333
:file:`configure` script.
3434

3535
.. versionchanged:: 3.1
@@ -58,6 +58,9 @@ Features and minimum versions required to build CPython:
5858
.. versionchanged:: 3.13
5959
Autoconf 2.71, aclocal 1.16.5 and SQLite 3.15.2 are now required.
6060

61+
.. versionchanged:: next
62+
Autoconf 2.72 is now required.
63+
6164
See also :pep:`7` "Style Guide for C Code" and :pep:`11` "CPython platform
6265
support".
6366

Include/cpython/unicodeobject.h

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ typedef struct {
109109
3: Interned, Immortal, and Static
110110
This categorization allows the runtime to determine the right
111111
cleanup mechanism at runtime shutdown. */
112-
unsigned int interned:2;
112+
uint16_t interned;
113113
/* Character size:
114114
115115
- PyUnicode_1BYTE_KIND (1):
@@ -132,21 +132,23 @@ typedef struct {
132132
* all characters are in the range U+0000-U+10FFFF
133133
* at least one character is in the range U+10000-U+10FFFF
134134
*/
135-
unsigned int kind:3;
135+
unsigned short kind:3;
136136
/* Compact is with respect to the allocation scheme. Compact unicode
137137
objects only require one memory block while non-compact objects use
138138
one block for the PyUnicodeObject struct and another for its data
139139
buffer. */
140-
unsigned int compact:1;
140+
unsigned short compact:1;
141141
/* The string only contains characters in the range U+0000-U+007F (ASCII)
142142
and the kind is PyUnicode_1BYTE_KIND. If ascii is set and compact is
143143
set, use the PyASCIIObject structure. */
144-
unsigned int ascii:1;
144+
unsigned short ascii:1;
145145
/* The object is statically allocated. */
146-
unsigned int statically_allocated:1;
146+
unsigned short statically_allocated:1;
147147
/* Padding to ensure that PyUnicode_DATA() is always aligned to
148-
4 bytes (see issue #19537 on m68k). */
149-
unsigned int :24;
148+
4 bytes (see issue #19537 on m68k) and we use unsigned short to avoid
149+
the extra four bytes on 32-bit Windows. This is restricted features
150+
for specific compilers including GCC, MSVC, Clang and IBM's XL compiler. */
151+
unsigned short :10;
150152
} state;
151153
} PyASCIIObject;
152154

@@ -195,7 +197,11 @@ typedef struct {
195197

196198
/* Use only if you know it's a string */
197199
static inline unsigned int PyUnicode_CHECK_INTERNED(PyObject *op) {
200+
#ifdef Py_GIL_DISABLED
201+
return _Py_atomic_load_uint16_relaxed(&_PyASCIIObject_CAST(op)->state.interned);
202+
#else
198203
return _PyASCIIObject_CAST(op)->state.interned;
204+
#endif
199205
}
200206
#define PyUnicode_CHECK_INTERNED(op) PyUnicode_CHECK_INTERNED(_PyObject_CAST(op))
201207

Lib/_pydatetime.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2392,7 +2392,6 @@ def __reduce__(self):
23922392

23932393
def _isoweek1monday(year):
23942394
# Helper to calculate the day number of the Monday starting week 1
2395-
# XXX This could be done more efficiently
23962395
THURSDAY = 3
23972396
firstday = _ymd2ord(year, 1, 1)
23982397
firstweekday = (firstday + 6) % 7 # See weekday() above

Lib/pathlib/_abc.py

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -573,30 +573,3 @@ def copy_into(self, target_dir, *, follow_symlinks=True,
573573
return self.copy(target, follow_symlinks=follow_symlinks,
574574
dirs_exist_ok=dirs_exist_ok,
575575
preserve_metadata=preserve_metadata)
576-
577-
def _delete(self):
578-
"""
579-
Delete this file or directory (including all sub-directories).
580-
"""
581-
raise NotImplementedError
582-
583-
def move(self, target):
584-
"""
585-
Recursively move this file or directory tree to the given destination.
586-
"""
587-
target = self.copy(target, follow_symlinks=False, preserve_metadata=True)
588-
self._delete()
589-
return target
590-
591-
def move_into(self, target_dir):
592-
"""
593-
Move this file or directory tree into the given existing directory.
594-
"""
595-
name = self.name
596-
if not name:
597-
raise ValueError(f"{self!r} has an empty name")
598-
elif isinstance(target_dir, PathBase):
599-
target = target_dir / name
600-
else:
601-
target = self.with_segments(target_dir, name)
602-
return self.move(target)

Lib/pathlib/_local.py

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1128,16 +1128,38 @@ def move(self, target):
11281128
"""
11291129
Recursively move this file or directory tree to the given destination.
11301130
"""
1131-
if not isinstance(target, PathBase):
1132-
target = self.with_segments(target)
1133-
target.copy._ensure_different_file(self)
1131+
# Use os.replace() if the target is os.PathLike and on the same FS.
11341132
try:
1135-
return self.replace(target)
1136-
except OSError as err:
1137-
if err.errno != EXDEV:
1138-
raise
1133+
target_str = os.fspath(target)
1134+
except TypeError:
1135+
pass
1136+
else:
1137+
if not isinstance(target, PathBase):
1138+
target = self.with_segments(target_str)
1139+
target.copy._ensure_different_file(self)
1140+
try:
1141+
os.replace(self, target_str)
1142+
return target
1143+
except OSError as err:
1144+
if err.errno != EXDEV:
1145+
raise
11391146
# Fall back to copy+delete.
1140-
return PathBase.move(self, target)
1147+
target = self.copy(target, follow_symlinks=False, preserve_metadata=True)
1148+
self._delete()
1149+
return target
1150+
1151+
def move_into(self, target_dir):
1152+
"""
1153+
Move this file or directory tree into the given existing directory.
1154+
"""
1155+
name = self.name
1156+
if not name:
1157+
raise ValueError(f"{self!r} has an empty name")
1158+
elif isinstance(target_dir, PathBase):
1159+
target = target_dir / name
1160+
else:
1161+
target = self.with_segments(target_dir, name)
1162+
return self.move(target)
11411163

11421164
if hasattr(os, "symlink"):
11431165
def symlink_to(self, target, target_is_directory=False):

0 commit comments

Comments
 (0)