Skip to content

Commit fba4c4b

Browse files
committed
Merge branch 'main' into fix-issue-132971
2 parents df20e17 + 4e294f6 commit fba4c4b

File tree

107 files changed

+3423
-1201
lines changed

Some content is hidden

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

107 files changed

+3423
-1201
lines changed

.github/workflows/mypy.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@ on:
88
pull_request:
99
paths:
1010
- ".github/workflows/mypy.yml"
11+
- "Lib/_colorize.py"
1112
- "Lib/_pyrepl/**"
1213
- "Lib/test/libregrtest/**"
14+
- "Misc/mypy/**"
1315
- "Tools/build/generate_sbom.py"
1416
- "Tools/cases_generator/**"
1517
- "Tools/clinic/**"

Doc/c-api/init.rst

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,16 +1517,6 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
15171517
.. versionadded:: 3.8
15181518
15191519
1520-
.. c:function:: PyObject* PyUnstable_InterpreterState_GetMainModule(PyInterpreterState *interp)
1521-
1522-
Return a :term:`strong reference` to the ``__main__`` :ref:`module object <moduleobjects>`
1523-
for the given interpreter.
1524-
1525-
The caller must have an :term:`attached thread state`.
1526-
1527-
.. versionadded:: 3.13
1528-
1529-
15301520
.. c:type:: PyObject* (*_PyFrameEvalFunction)(PyThreadState *tstate, _PyInterpreterFrame *frame, int throwflag)
15311521
15321522
Type of a frame evaluation function.

Doc/c-api/unicode.rst

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,14 @@ Python:
3333

3434
.. c:var:: PyTypeObject PyUnicode_Type
3535
36-
This instance of :c:type:`PyTypeObject` represents the Python Unicode type. It
37-
is exposed to Python code as :py:class:`str`.
36+
This instance of :c:type:`PyTypeObject` represents the Python Unicode type.
37+
It is exposed to Python code as :py:class:`str`.
38+
39+
40+
.. c:var:: PyTypeObject PyUnicodeIter_Type
41+
42+
This instance of :c:type:`PyTypeObject` represents the Python Unicode
43+
iterator type. It is used to iterate over Unicode string objects.
3844

3945

4046
.. c:type:: Py_UCS4

Doc/deprecations/pending-removal-in-future.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ although there is currently no date scheduled for their removal.
1313
deprecated.
1414
* The :class:`argparse.FileType` type converter is deprecated.
1515

16-
* :mod:`array`'s ``'u'`` format code (:gh:`57281`)
17-
1816
* :mod:`builtins`:
1917

2018
* ``bool(NotImplemented)``.
@@ -49,6 +47,8 @@ although there is currently no date scheduled for their removal.
4947
:data:`calendar.FEBRUARY`.
5048
(Contributed by Prince Roshan in :gh:`103636`.)
5149

50+
* :mod:`codecs`: use :func:`open` instead of :func:`codecs.open`. (:gh:`133038`)
51+
5252
* :attr:`codeobject.co_lnotab`: use the :meth:`codeobject.co_lines` method
5353
instead.
5454

Doc/library/codecs.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,10 @@ wider range of codecs when working with binary files:
208208
.. versionchanged:: 3.11
209209
The ``'U'`` mode has been removed.
210210

211+
.. deprecated:: next
212+
213+
:func:`codecs.open` has been superseded by :func:`open`.
214+
211215

212216
.. function:: EncodedFile(file, data_encoding, file_encoding=None, errors='strict')
213217

Doc/library/pdb.rst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,21 @@ slightly different way:
188188
.. versionadded:: 3.14
189189
The *commands* argument.
190190

191+
192+
.. awaitablefunction:: set_trace_async(*, header=None, commands=None)
193+
194+
async version of :func:`set_trace`. This function should be used inside an
195+
async function with :keyword:`await`.
196+
197+
.. code-block:: python
198+
199+
async def f():
200+
await pdb.set_trace_async()
201+
202+
:keyword:`await` statements are supported if the debugger is invoked by this function.
203+
204+
.. versionadded:: 3.14
205+
191206
.. function:: post_mortem(t=None)
192207

193208
Enter post-mortem debugging of the given exception or

Doc/whatsnew/3.14.rst

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1168,6 +1168,11 @@ pdb
11681168
backend by default, which is configurable.
11691169
(Contributed by Tian Gao in :gh:`124533`.)
11701170

1171+
* :func:`pdb.set_trace_async` is added to support debugging asyncio
1172+
coroutines. :keyword:`await` statements are supported with this
1173+
function.
1174+
(Contributed by Tian Gao in :gh:`132576`.)
1175+
11711176

11721177
pickle
11731178
------
@@ -1592,6 +1597,10 @@ Deprecated
15921597
as a single positional argument.
15931598
(Contributed by Serhiy Storchaka in :gh:`109218`.)
15941599

1600+
* :mod:`codecs`:
1601+
:func:`codecs.open` is now deprecated. Use :func:`open` instead.
1602+
(Contributed by Inada Naoki in :gh:`133036`.)
1603+
15951604
* :mod:`functools`:
15961605
Calling the Python implementation of :func:`functools.reduce` with *function*
15971606
or *sequence* as keyword arguments is now deprecated.
@@ -1637,6 +1646,13 @@ Deprecated
16371646
Deprecate :meth:`symtable.Class.get_methods` due to the lack of interest.
16381647
(Contributed by Bénédikt Tran in :gh:`119698`.)
16391648

1649+
* :mod:`tkinter`:
1650+
The :class:`!tkinter.Variable` methods :meth:`!trace_variable`,
1651+
:meth:`!trace_vdelete` and :meth:`!trace_vinfo` are now deprecated.
1652+
Use :meth:`!trace_add`, :meth:`!trace_remove` and :meth:`!trace_info`
1653+
instead.
1654+
(Contributed by Serhiy Storchaka in :gh:`120220`.)
1655+
16401656
* :mod:`urllib.parse`:
16411657
Accepting objects with false values (like ``0`` and ``[]``) except empty
16421658
strings, byte-like objects and ``None`` in :mod:`urllib.parse` functions
@@ -2280,3 +2296,10 @@ Removed
22802296
* Remove the private ``_Py_InitializeMain()`` function. It was a
22812297
:term:`provisional API` added to Python 3.8 by :pep:`587`.
22822298
(Contributed by Victor Stinner in :gh:`129033`.)
2299+
2300+
* The undocumented APIs :c:macro:`!Py_C_RECURSION_LIMIT` and
2301+
:c:member:`!PyThreadState.c_recursion_remaining`, added in 3.13, are removed
2302+
without a deprecation period.
2303+
Please use :c:func:`Py_EnterRecursiveCall` to guard against runaway recursion
2304+
in C code.
2305+
(Removed in :gh:`133079`, see also :gh:`130396`.)

Include/cpython/pystate.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
PyAPI_FUNC(int) _PyInterpreterState_RequiresIDRef(PyInterpreterState *);
99
PyAPI_FUNC(void) _PyInterpreterState_RequireIDRef(PyInterpreterState *, int);
1010

11-
PyAPI_FUNC(PyObject *) PyUnstable_InterpreterState_GetMainModule(PyInterpreterState *);
12-
1311
/* State unique per thread */
1412

1513
/* Py_tracefunc return -1 when raising an exception, or 0 for success. */
@@ -120,8 +118,6 @@ struct _ts {
120118

121119
int py_recursion_remaining;
122120
int py_recursion_limit;
123-
124-
int c_recursion_remaining; /* Retained for backwards compatibility. Do not use */
125121
int recursion_headroom; /* Allow 50 more calls to handle any errors. */
126122

127123
/* 'tracing' keeps track of the execution depth when tracing/profiling.
@@ -212,8 +208,6 @@ struct _ts {
212208
_PyRemoteDebuggerSupport remote_debugger_support;
213209
};
214210

215-
# define Py_C_RECURSION_LIMIT 5000
216-
217211
/* other API */
218212

219213
/* Similar to PyThreadState_Get(), but don't issue a fatal error

Include/internal/pycore_code.h

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -177,12 +177,14 @@ typedef struct {
177177
*/
178178

179179
// Note that these all fit within a byte, as do combinations.
180-
// Later, we will use the smaller numbers to differentiate the different
181-
// kinds of locals (e.g. pos-only arg, varkwargs, local-only).
182-
#define CO_FAST_HIDDEN 0x10
183-
#define CO_FAST_LOCAL 0x20
184-
#define CO_FAST_CELL 0x40
185-
#define CO_FAST_FREE 0x80
180+
#define CO_FAST_ARG_POS (0x02) // pos-only, pos-or-kw, varargs
181+
#define CO_FAST_ARG_KW (0x04) // kw-only, pos-or-kw, varkwargs
182+
#define CO_FAST_ARG_VAR (0x08) // varargs, varkwargs
183+
#define CO_FAST_ARG (CO_FAST_ARG_POS | CO_FAST_ARG_KW | CO_FAST_ARG_VAR)
184+
#define CO_FAST_HIDDEN (0x10)
185+
#define CO_FAST_LOCAL (0x20)
186+
#define CO_FAST_CELL (0x40)
187+
#define CO_FAST_FREE (0x80)
186188

187189
typedef unsigned char _PyLocals_Kind;
188190

@@ -315,6 +317,7 @@ extern void _Py_Specialize_ForIter(_PyStackRef iter, _Py_CODEUNIT *instr, int op
315317
extern void _Py_Specialize_Send(_PyStackRef receiver, _Py_CODEUNIT *instr);
316318
extern void _Py_Specialize_ToBool(_PyStackRef value, _Py_CODEUNIT *instr);
317319
extern void _Py_Specialize_ContainsOp(_PyStackRef value, _Py_CODEUNIT *instr);
320+
extern void _Py_GatherStats_GetIter(_PyStackRef iterable);
318321

319322
// Utility functions for reading/writing 32/64-bit values in the inline caches.
320323
// Great care should be taken to ensure that these functions remain correct and
@@ -561,6 +564,10 @@ extern void _Py_ClearTLBCIndex(_PyThreadStateImpl *tstate);
561564
extern int _Py_ClearUnusedTLBC(PyInterpreterState *interp);
562565
#endif
563566

567+
568+
PyAPI_FUNC(int) _PyCode_ReturnsOnlyNone(PyCodeObject *);
569+
570+
564571
#ifdef __cplusplus
565572
}
566573
#endif

Include/internal/pycore_crossinterp.h

Lines changed: 63 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ struct _xidata {
5757
// likely a registered "xidatafunc", is responsible for
5858
// ensuring it owns the reference (i.e. incref).
5959
PyObject *obj;
60-
// interp is the ID of the owning interpreter of the original
60+
// interpid is the ID of the owning interpreter of the original
6161
// object. It corresponds to the active interpreter when
6262
// _PyObject_GetXIData() was called. This should only
6363
// be set by the cross-interpreter machinery.
@@ -93,37 +93,6 @@ PyAPI_FUNC(void) _PyXIData_Free(_PyXIData_t *data);
9393
// Users should not need getters for "new_object" or "free".
9494

9595

96-
/* getting cross-interpreter data */
97-
98-
typedef int (*xidatafunc)(PyThreadState *tstate, PyObject *, _PyXIData_t *);
99-
100-
PyAPI_FUNC(PyObject *) _PyXIData_GetNotShareableErrorType(PyThreadState *);
101-
PyAPI_FUNC(void) _PyXIData_SetNotShareableError(PyThreadState *, const char *);
102-
PyAPI_FUNC(void) _PyXIData_FormatNotShareableError(
103-
PyThreadState *,
104-
const char *,
105-
...);
106-
107-
PyAPI_FUNC(xidatafunc) _PyXIData_Lookup(
108-
PyThreadState *,
109-
PyObject *);
110-
PyAPI_FUNC(int) _PyObject_CheckXIData(
111-
PyThreadState *,
112-
PyObject *);
113-
114-
PyAPI_FUNC(int) _PyObject_GetXIData(
115-
PyThreadState *,
116-
PyObject *,
117-
_PyXIData_t *);
118-
119-
120-
/* using cross-interpreter data */
121-
122-
PyAPI_FUNC(PyObject *) _PyXIData_NewObject(_PyXIData_t *);
123-
PyAPI_FUNC(int) _PyXIData_Release(_PyXIData_t *);
124-
PyAPI_FUNC(int) _PyXIData_ReleaseAndRawFree(_PyXIData_t *);
125-
126-
12796
/* defining cross-interpreter data */
12897

12998
PyAPI_FUNC(void) _PyXIData_Init(
@@ -134,7 +103,7 @@ PyAPI_FUNC(int) _PyXIData_InitWithSize(
134103
_PyXIData_t *,
135104
PyInterpreterState *interp, const size_t, PyObject *,
136105
xid_newobjfunc);
137-
PyAPI_FUNC(void) _PyXIData_Clear( PyInterpreterState *, _PyXIData_t *);
106+
PyAPI_FUNC(void) _PyXIData_Clear(PyInterpreterState *, _PyXIData_t *);
138107

139108
// Normally the Init* functions are sufficient. The only time
140109
// additional initialization might be needed is to set the "free" func,
@@ -143,6 +112,8 @@ PyAPI_FUNC(void) _PyXIData_Clear( PyInterpreterState *, _PyXIData_t *);
143112
do { \
144113
(DATA)->free = (FUNC); \
145114
} while (0)
115+
#define _PyXIData_CHECK_FREE(DATA, FUNC) \
116+
((DATA)->free == (FUNC))
146117
// Additionally, some shareable types are essentially light wrappers
147118
// around other shareable types. The xidatafunc of the wrapper
148119
// can often be implemented by calling the wrapped object's
@@ -154,6 +125,65 @@ PyAPI_FUNC(void) _PyXIData_Clear( PyInterpreterState *, _PyXIData_t *);
154125
do { \
155126
(DATA)->new_object = (FUNC); \
156127
} while (0)
128+
#define _PyXIData_CHECK_NEW_OBJECT(DATA, FUNC) \
129+
((DATA)->new_object == (FUNC))
130+
131+
132+
/* getting cross-interpreter data */
133+
134+
typedef int (*xidatafunc)(PyThreadState *tstate, PyObject *, _PyXIData_t *);
135+
136+
PyAPI_FUNC(PyObject *) _PyXIData_GetNotShareableErrorType(PyThreadState *);
137+
PyAPI_FUNC(void) _PyXIData_SetNotShareableError(PyThreadState *, const char *);
138+
PyAPI_FUNC(void) _PyXIData_FormatNotShareableError(
139+
PyThreadState *,
140+
const char *,
141+
...);
142+
143+
PyAPI_FUNC(xidatafunc) _PyXIData_Lookup(
144+
PyThreadState *,
145+
PyObject *);
146+
PyAPI_FUNC(int) _PyObject_CheckXIData(
147+
PyThreadState *,
148+
PyObject *);
149+
150+
PyAPI_FUNC(int) _PyObject_GetXIData(
151+
PyThreadState *,
152+
PyObject *,
153+
_PyXIData_t *);
154+
155+
// _PyObject_GetXIData() for bytes
156+
typedef struct {
157+
const char *bytes;
158+
Py_ssize_t len;
159+
} _PyBytes_data_t;
160+
PyAPI_FUNC(int) _PyBytes_GetData(PyObject *, _PyBytes_data_t *);
161+
PyAPI_FUNC(PyObject *) _PyBytes_FromData(_PyBytes_data_t *);
162+
PyAPI_FUNC(PyObject *) _PyBytes_FromXIData(_PyXIData_t *);
163+
PyAPI_FUNC(int) _PyBytes_GetXIData(
164+
PyThreadState *,
165+
PyObject *,
166+
_PyXIData_t *);
167+
PyAPI_FUNC(_PyBytes_data_t *) _PyBytes_GetXIDataWrapped(
168+
PyThreadState *,
169+
PyObject *,
170+
size_t,
171+
xid_newobjfunc,
172+
_PyXIData_t *);
173+
174+
// _PyObject_GetXIData() for marshal
175+
PyAPI_FUNC(PyObject *) _PyMarshal_ReadObjectFromXIData(_PyXIData_t *);
176+
PyAPI_FUNC(int) _PyMarshal_GetXIData(
177+
PyThreadState *,
178+
PyObject *,
179+
_PyXIData_t *);
180+
181+
182+
/* using cross-interpreter data */
183+
184+
PyAPI_FUNC(PyObject *) _PyXIData_NewObject(_PyXIData_t *);
185+
PyAPI_FUNC(int) _PyXIData_Release(_PyXIData_t *);
186+
PyAPI_FUNC(int) _PyXIData_ReleaseAndRawFree(_PyXIData_t *);
157187

158188

159189
/* cross-interpreter data registry */

0 commit comments

Comments
 (0)