Skip to content

Commit b5c70b5

Browse files
authored
Merge branch 'python:main' into doc-regrtest-unittest-loader
2 parents 9890bcb + 1b015e6 commit b5c70b5

90 files changed

Lines changed: 2907 additions & 1412 deletions

File tree

Some content is hidden

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

‎Doc/c-api/exceptions.rst‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,6 +1034,10 @@ because the :ref:`call protocol <call>` takes care of recursion handling.
10341034
case, a :exc:`RecursionError` is set and a nonzero value is returned.
10351035
Otherwise, zero is returned.
10361036
1037+
The check is based on the remaining C stack space of the current thread,
1038+
not on a count of calls, so it is unaffected by
1039+
:c:func:`Py_SetRecursionLimit` and :func:`sys.setrecursionlimit`.
1040+
10371041
*where* should be a UTF-8 encoded string such as ``" in instance check"`` to
10381042
be concatenated to the :exc:`RecursionError` message caused by the recursion
10391043
depth limit.
@@ -1044,6 +1048,10 @@ because the :ref:`call protocol <call>` takes care of recursion handling.
10441048
.. versionchanged:: 3.9
10451049
This function is now also available in the :ref:`limited API <limited-c-api>`.
10461050
1051+
.. versionchanged:: 3.14
1052+
The check is based on the remaining C stack space. Previously, a
1053+
separate counter of C-level calls was used.
1054+
10471055
.. c:function:: void Py_LeaveRecursiveCall(void)
10481056
10491057
Ends a :c:func:`Py_EnterRecursiveCall`. Must be called once for each

‎Doc/c-api/interp-lifecycle.rst‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ Process-wide parameters
514514
Return the version of this Python interpreter. This is a string that looks
515515
something like ::
516516
517-
"3.0a5+ (py3k:63103M, May 12 2008, 00:53:55) \n[GCC 4.2.3]"
517+
"3.15.0rc2 (3.15.0~rc2-1.fc44.x86_64, Sep 3 2026, 00:00:00) [GCC 16.2.1 20260819 (Red Hat 16.2.1-2)]"
518518
519519
.. index:: single: version (in module sys)
520520

‎Doc/howto/abi3t-migration.rst‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,9 +217,9 @@ Module export hook
217217

218218
Unless you've done this step already, your extension module defines a
219219
:ref:`module initialization function <extension-pyinit>`
220-
named :samp:`PyInit_{<module_name>}`.
220+
named :samp:`PyInit_{<modname>}` (where ``modname`` is the name of your module).
221221
You will need to port it to a :ref:`module export hook <extension-export-hook>`,
222-
:samp:`PyModExport_{<module name>}`, a feature added in CPython 3.15 in
222+
:samp:`PyModExport_{<modname>}`, a feature added in CPython 3.15 in
223223
:pep:`793`.
224224

225225
Your existing init function should look like this (with your own names
@@ -297,6 +297,34 @@ pointer to static data.
297297
If you cannot avoid additional code, refer to the
298298
:ref:`caveats in PyModExport documentation <pymodexport-api-caveats>`.
299299

300+
.. note::
301+
302+
When building for Windows using the Setuptools_ build tool,
303+
removing the :samp:`PyInit_{<modname>}` function may result in the linker error
304+
:samp:`LINK : error LNK2001: unresolved external symbol PyInit_{<modname>}`.
305+
This is caused by Setuptools passing an ``/EXPORT`` linker flag, which
306+
is redundant since Python 3.15 (see :gh:`141671`).
307+
A workaround is to add a dummy :samp:`PyInit_{<modname>}` function
308+
to your code.
309+
Python 3.15+ will never call this function if
310+
:samp:`PyModExport_{<modname>}` is present, so it can always fail:
311+
312+
.. code-block:: c
313+
314+
// Workaround for https://github.com/pypa/distutils/issues/387
315+
PyMODINIT_FUNC
316+
PyInit_<modname>(void)
317+
{
318+
PyErr_SetString(PyExc_SystemError,
319+
"PyInit_* called for module with PyModExport_*");
320+
return NULL;
321+
}
322+
323+
(This issue is present in Setuptools 84.0.0; it might be fixed in newer
324+
versions.)
325+
326+
.. _Setuptools: https://setuptools.pypa.io/
327+
300328

301329
Existing slots
302330
--------------

‎Doc/library/codecs.rst‎

Lines changed: 21 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1395,15 +1395,6 @@ encodings.
13951395
| | | :mod:`encodings.idna`. |
13961396
| | | Only ``errors='strict'`` |
13971397
| | | is supported. |
1398-
| | | |
1399-
| | | .. warning:: |
1400-
| | | |
1401-
| | | This codec builds on |
1402-
| | | ``punycode``, whose |
1403-
| | | algorithms scale |
1404-
| | | poorly, so limit the |
1405-
| | | length of untrusted |
1406-
| | | input. |
14071398
+--------------------+---------+---------------------------+
14081399
| mbcs | ansi, | Windows only: Encode the |
14091400
| | dbcs | operand according to the |
@@ -1655,11 +1646,6 @@ Applications) and :rfc:`3492` (Nameprep: A Stringprep Profile for
16551646
Internationalized Domain Names (IDN)). It builds upon the ``punycode`` encoding
16561647
and :mod:`stringprep`.
16571648

1658-
.. warning::
1659-
1660-
This module builds on ``punycode``, whose algorithms scale poorly, so limit
1661-
the length of untrusted input.
1662-
16631649
If you need the IDNA 2008 standard from :rfc:`5891` and :rfc:`5895`, use the
16641650
third-party :pypi:`idna` module.
16651651

@@ -1697,11 +1683,31 @@ international domain names, and to unify similar characters. The nameprep
16971683
functions can be used directly if desired.
16981684

16991685

1700-
.. function:: nameprep(label)
1686+
.. function:: nameprep(label, *, limit=None)
17011687

17021688
Return the nameprepped version of *label*. The implementation currently assumes
17031689
query strings, so ``AllowUnassigned`` is true.
17041690

1691+
Raise :exc:`UnicodeEncodeError` if the nameprep algorithm emits an error.
1692+
1693+
If the *limit* argument is given, it should be set to the maximum size
1694+
of an encoded A-label (that is, 63 for IDNA).
1695+
:func:`!nameprep` will raise :exc:`UnicodeEncodeError` if the label is
1696+
**much** larger than *limit*.
1697+
Note that this is only a rough check meant to skip expensive processing
1698+
of extremely large input; the caller should check any exact
1699+
limits separately.
1700+
1701+
.. warning::
1702+
1703+
For backwards compatibility, label size is unlimited by default.
1704+
This may cause issues when processing the result with the
1705+
``punycode`` encoding, whose algorithms scale poorly.
1706+
1707+
.. versionchanged:: next
1708+
1709+
Added the *limit* parameter.
1710+
17051711

17061712
.. function:: ToASCII(label)
17071713

‎Doc/whatsnew/3.15.rst‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,10 @@ name:
188188
lazy import json
189189
lazy from pathlib import Path
190190
191-
print("Starting up...") # json and pathlib not loaded yet
191+
print("Starting up...") # json and pathlib are not fully imported yet
192192
193-
data = json.loads('{"key": "value"}') # json loads here
194-
p = Path(".") # pathlib loads here
193+
data = json.loads('{"key": "value"}') # json gets fully imported here
194+
p = Path(".") # pathlib gets fully imported here
195195
196196
This mechanism is particularly useful for applications that import many
197197
modules at the top level but may only use a subset of them in any given run.

‎Doc/whatsnew/3.16.rst‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -397,6 +397,10 @@ encodings
397397
used for international IMAP4 mailbox names (:rfc:`3501`).
398398
(Contributed by Serhiy Storchaka in :gh:`66788`.)
399399

400+
* :func:`encodings.idna.nameprep` now takes a *limit* argument that allows
401+
rejecting extremely large input early.
402+
(Contributed by Petr Viktorin in :gh:`157675`.)
403+
400404

401405
gzip
402406
----

‎Include/internal/pycore_dict.h‎

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,11 @@ PyAPI_FUNC(int) _PyDict_DelItemIf(PyObject *mp, PyObject *key,
2323
int (*predicate)(PyObject *value, void *arg),
2424
void *arg);
2525

26+
// Atomically replace an existing value if it is expected (by identity).
27+
// Return 1 if replaced, 0 if absent or different, or -1 on error.
28+
extern int _PyDict_ReplaceItemIf(PyObject *dict, PyObject *key,
29+
PyObject *expected, PyObject *replacement);
30+
2631
// "KnownHash" variants
2732
// Export for '_asyncio' shared extension
2833
PyAPI_FUNC(int) _PyDict_SetItem_KnownHash(PyObject *mp, PyObject *key,
@@ -147,8 +152,8 @@ PyAPI_FUNC(Py_ssize_t) _PyDictKeys_StringLookup(PyDictKeysObject* dictkeys, PyOb
147152
*/
148153
PyAPI_FUNC(Py_ssize_t) _PyDictKeys_StringLookupAndVersion(PyDictKeysObject* dictkeys, PyObject *key, uint32_t *version);
149154
PyAPI_FUNC(Py_ssize_t) _PyDictKeys_StringLookupSplit(PyDictKeysObject* dictkeys, PyObject *key);
150-
PyAPI_FUNC(PyObject *)_PyDict_LoadGlobal(PyDictObject *, PyDictObject *, PyObject *);
151-
PyAPI_FUNC(void) _PyDict_LoadGlobalStackRef(PyDictObject *, PyDictObject *, PyObject *, _PyStackRef *);
155+
// Return the borrowed source dictionary, or NULL if absent or on error.
156+
PyAPI_FUNC(PyObject *) _PyDict_LoadGlobalStackRef(PyDictObject *, PyDictObject *, PyObject *, _PyStackRef *);
152157

153158
// Loads the __builtins__ object from the globals dict. Returns a new reference.
154159
extern PyObject *_PyDict_LoadBuiltinsFromGlobals(PyObject *globals);

‎Include/internal/pycore_getopt.h‎

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@
55
# error "this header requires Py_BUILD_CORE define"
66
#endif
77

8-
extern int _PyOS_opterr;
9-
extern Py_ssize_t _PyOS_optind;
10-
extern const wchar_t *_PyOS_optarg;
8+
struct _PyOS_GetOpt {
9+
int error; // generate error messages
10+
Py_ssize_t index; // index into argv array
11+
const wchar_t *arg; // optional argument
12+
const wchar_t *ptr;
13+
Py_ssize_t argc;
14+
wchar_t * const *argv;
15+
};
1116

12-
extern void _PyOS_ResetGetOpt(void);
17+
extern void _PyOS_GetOpt_Init(
18+
struct _PyOS_GetOpt *getopt,
19+
Py_ssize_t argc,
20+
wchar_t * const *argv);
1321

14-
typedef struct {
15-
const wchar_t *name;
16-
int has_arg;
17-
int val;
18-
} _PyOS_LongOption;
19-
20-
extern int _PyOS_GetOpt(Py_ssize_t argc, wchar_t * const *argv, int *longindex);
22+
extern int _PyOS_GetOpt(
23+
struct _PyOS_GetOpt *getopt);
2124

2225
#endif /* !Py_INTERNAL_PYGETOPT_H */

‎Include/internal/pycore_import.h‎

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,18 @@ extern int _PyImport_FixupBuiltin(
3232
PyObject *modules
3333
);
3434

35-
extern PyObject * _PyImport_ResolveName(
36-
PyThreadState *tstate, PyObject *name, PyObject *globals, int level);
3735
extern PyObject * _PyImport_GetAbsName(
3836
PyThreadState *tstate, PyObject *name, PyObject *globals, int level);
3937
// Symbol is exported for the JIT on Windows builds.
4038
PyAPI_FUNC(PyObject *) _PyImport_LoadLazyImportTstate(
4139
PyThreadState *tstate, PyObject *lazy_import);
42-
typedef enum {
43-
_Py_LAZY_SUBMODULE_ERROR = -1,
44-
_Py_LAZY_SUBMODULE_NOT_FOUND = 0,
45-
_Py_LAZY_SUBMODULE_LOADED = 1,
46-
} _PyLazySubmoduleImportResult;
47-
extern _PyLazySubmoduleImportResult _PyImport_TryLoadLazySubmodule(
48-
PyObject *mod_name, PyObject *attr_name, PyObject **result);
40+
// Bind a pending child on module before removing its registration. Return a
41+
// new reference, NULL without an exception if absent, or NULL on error.
42+
// Set recheck_dict if a concurrent lookup may have already bound the child.
43+
extern PyObject * _PyImport_TryLoadLazySubmodule(
44+
PyObject *module, PyObject *attr_name, int suppress, int *recheck_dict);
45+
extern int _PyImport_ClearLazySubmodule(
46+
PyThreadState *tstate, PyObject *name, int bind);
4947
extern PyObject * _PyImport_LazyImportModuleLevelObject(
5048
PyThreadState *tstate, PyObject *name, PyObject *builtins,
5149
PyObject *globals, PyObject *locals, PyObject *fromlist, int level);
@@ -91,6 +89,8 @@ extern void _PyImport_ClearModulesByIndex(PyInterpreterState *interp);
9189
extern PyObject * _PyImport_InitLazyModules(
9290
PyInterpreterState *interp);
9391
extern void _PyImport_ClearLazyModules(PyInterpreterState *interp);
92+
extern int _PyImport_DiscardLazyModule(
93+
PyInterpreterState *interp, PyObject *name);
9494

9595
extern int _PyImport_InitDefaultImportFunc(PyInterpreterState *interp);
9696
extern int _PyImport_IsDefaultImportFunc(

‎Include/internal/pycore_interp_structs.h‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,16 +352,15 @@ struct _import_state {
352352
PyObject *lazy_import_func;
353353
int lazy_imports_mode;
354354
PyObject *lazy_imports_filter;
355-
PyObject *lazy_importing_modules;
356355
// The set stored in sys.lazy_modules if values that have been
357356
// lazily imported. This value is only for debugging/introspection
358357
// purposes and is not used by the runtime.
359358
PyObject *lazy_modules;
360-
// A dict mapping package names to a set of submodule names that
361-
// have been imported lazily from packages which have been imported
362-
// lazily. When the package is reified we need to add a
363-
// LazyImportObject which refers to the submodule on the module.
359+
// Package names map to pending children: declarations for plain imports,
360+
// or None for from-import names that may be ordinary attributes.
364361
PyObject *lazy_pending_submodules;
362+
// Avoid pending-child work for ordinary cached imports.
363+
int has_lazy_submodules;
365364
#ifdef Py_GIL_DISABLED
366365
PyMutex lazy_mutex;
367366
#endif

0 commit comments

Comments
 (0)