Skip to content

Commit cfa6fe9

Browse files
Merge branch 'main' into slots-after-items
2 parents a452fce + f15f6d0 commit cfa6fe9

Some content is hidden

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

54 files changed

+5899
-174
lines changed

Doc/c-api/datetime.rst

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,42 @@ DateTime Objects
88
Various date and time objects are supplied by the :mod:`datetime` module.
99
Before using any of these functions, the header file :file:`datetime.h` must be
1010
included in your source (note that this is not included by :file:`Python.h`),
11-
and the macro :c:macro:`!PyDateTime_IMPORT` must be invoked, usually as part of
11+
and the macro :c:macro:`PyDateTime_IMPORT` must be invoked, usually as part of
1212
the module initialisation function. The macro puts a pointer to a C structure
13-
into a static variable, :c:data:`!PyDateTimeAPI`, that is used by the following
13+
into a static variable, :c:data:`PyDateTimeAPI`, that is used by the following
1414
macros.
1515

16+
.. c:macro:: PyDateTime_IMPORT()
17+
18+
Import the datetime C API.
19+
20+
On success, populate the :c:var:`PyDateTimeAPI` pointer.
21+
On failure, set :c:var:`PyDateTimeAPI` to ``NULL`` and set an exception.
22+
The caller must check if an error occurred via :c:func:`PyErr_Occurred`:
23+
24+
.. code-block::
25+
26+
PyDateTime_IMPORT;
27+
if (PyErr_Occurred()) { /* cleanup */ }
28+
29+
.. warning::
30+
31+
This is not compatible with subinterpreters.
32+
33+
.. c:type:: PyDateTime_CAPI
34+
35+
Structure containing the fields for the datetime C API.
36+
37+
The fields of this structure are private and subject to change.
38+
39+
Do not use this directly; prefer ``PyDateTime_*`` APIs instead.
40+
41+
.. c:var:: PyDateTime_CAPI *PyDateTimeAPI
42+
43+
Dynamically allocated object containing the datetime C API.
44+
45+
This variable is only available once :c:macro:`PyDateTime_IMPORT` succeeds.
46+
1647
.. c:type:: PyDateTime_Date
1748
1849
This subtype of :c:type:`PyObject` represents a Python date object.
@@ -325,3 +356,16 @@ Macros for the convenience of modules implementing the DB API:
325356
326357
Create and return a new :class:`datetime.date` object given an argument
327358
tuple suitable for passing to :meth:`datetime.date.fromtimestamp`.
359+
360+
361+
Internal data
362+
-------------
363+
364+
The following symbols are exposed by the C API but should be considered
365+
internal-only.
366+
367+
.. c:macro:: PyDateTime_CAPSULE_NAME
368+
369+
Name of the datetime capsule to pass to :c:func:`PyCapsule_Import`.
370+
371+
Internal usage only. Use :c:macro:`PyDateTime_IMPORT` instead.

Doc/c-api/gen.rst

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,3 +44,41 @@ than explicitly calling :c:func:`PyGen_New` or :c:func:`PyGen_NewWithQualName`.
4444
with ``__name__`` and ``__qualname__`` set to *name* and *qualname*.
4545
A reference to *frame* is stolen by this function. The *frame* argument
4646
must not be ``NULL``.
47+
48+
.. c:function:: PyCodeObject* PyGen_GetCode(PyGenObject *gen)
49+
50+
Return a new :term:`strong reference` to the code object wrapped by *gen*.
51+
This function always succeeds.
52+
53+
54+
Asynchronous Generator Objects
55+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
56+
57+
.. seealso::
58+
:pep:`525`
59+
60+
.. c:var:: PyTypeObject PyAsyncGen_Type
61+
62+
The type object corresponding to asynchronous generator objects. This is
63+
available as :class:`types.AsyncGeneratorType` in the Python layer.
64+
65+
.. versionadded:: 3.6
66+
67+
.. c:function:: PyObject *PyAsyncGen_New(PyFrameObject *frame, PyObject *name, PyObject *qualname)
68+
69+
Create a new asynchronous generator wrapping *frame*, with ``__name__`` and
70+
``__qualname__`` set to *name* and *qualname*. *frame* is stolen by this
71+
function and must not be ``NULL``.
72+
73+
On success, this function returns a :term:`strong reference` to the
74+
new asynchronous generator. On failure, this function returns ``NULL``
75+
with an exception set.
76+
77+
.. versionadded:: 3.6
78+
79+
.. c:function:: int PyAsyncGen_CheckExact(PyObject *op)
80+
81+
Return true if *op* is an asynchronous generator object, false otherwise.
82+
This function always succeeds.
83+
84+
.. versionadded:: 3.6

Doc/c-api/init.rst

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1891,6 +1891,25 @@ pointer and a void pointer argument.
18911891
This function now always schedules *func* to be run in the main
18921892
interpreter.
18931893
1894+
1895+
.. c:function:: int Py_MakePendingCalls(void)
1896+
1897+
Execute all pending calls. This is usually executed automatically by the
1898+
interpreter.
1899+
1900+
This function returns ``0`` on success, and returns ``-1`` with an exception
1901+
set on failure.
1902+
1903+
If this is not called in the main thread of the main
1904+
interpreter, this function does nothing and returns ``0``.
1905+
The caller must hold an :term:`attached thread state`.
1906+
1907+
.. versionadded:: 3.1
1908+
1909+
.. versionchanged:: 3.12
1910+
This function only runs pending calls in the main interpreter.
1911+
1912+
18941913
.. _profiling:
18951914
18961915
Profiling and Tracing

Doc/c-api/type.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -638,7 +638,7 @@ The following functions and structs are used to create
638638
under the :ref:`limited API <limited-c-api>`.
639639
640640
.. versionchanged:: 3.14
641-
The field :c:member:`~PyTypeObject.tp_vectorcall` can now set
641+
The field :c:member:`~PyTypeObject.tp_vectorcall` can now be set
642642
using :c:data:`Py_tp_vectorcall`. See the field's documentation
643643
for details.
644644

Doc/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@
361361

362362
# Grouping the document tree into LaTeX files. List of tuples
363363
# (source start file, target name, title, author, document class [howto/manual]).
364-
_stdauthor = 'Guido van Rossum and the Python development team'
364+
_stdauthor = 'The Python development team'
365365
latex_documents = [
366366
('c-api/index', 'c-api.tex', 'The Python/C API', _stdauthor, 'manual'),
367367
(

Doc/library/argparse.rst

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1322,20 +1322,25 @@ attribute is determined by the ``dest`` keyword argument of
13221322

13231323
For optional argument actions, the value of ``dest`` is normally inferred from
13241324
the option strings. :class:`ArgumentParser` generates the value of ``dest`` by
1325-
taking the first long option string and stripping away the initial ``--``
1326-
string. If no long option strings were supplied, ``dest`` will be derived from
1325+
taking the first double-dash long option string and stripping away the initial
1326+
``-`` characters.
1327+
If no double-dash long option strings were supplied, ``dest`` will be derived
1328+
from the first single-dash long option string by stripping the initial ``-``
1329+
character.
1330+
If no long option strings were supplied, ``dest`` will be derived from
13271331
the first short option string by stripping the initial ``-`` character. Any
13281332
internal ``-`` characters will be converted to ``_`` characters to make sure
13291333
the string is a valid attribute name. The examples below illustrate this
13301334
behavior::
13311335

13321336
>>> parser = argparse.ArgumentParser()
13331337
>>> parser.add_argument('-f', '--foo-bar', '--foo')
1338+
>>> parser.add_argument('-q', '-quz')
13341339
>>> parser.add_argument('-x', '-y')
1335-
>>> parser.parse_args('-f 1 -x 2'.split())
1336-
Namespace(foo_bar='1', x='2')
1337-
>>> parser.parse_args('--foo 1 -y 2'.split())
1338-
Namespace(foo_bar='1', x='2')
1340+
>>> parser.parse_args('-f 1 -q 2 -x 3'.split())
1341+
Namespace(foo_bar='1', quz='2', x='3')
1342+
>>> parser.parse_args('--foo 1 -quz 2 -y 3'.split())
1343+
Namespace(foo_bar='1', quz='2', x='2')
13391344

13401345
``dest`` allows a custom attribute name to be provided::
13411346

@@ -1344,6 +1349,9 @@ behavior::
13441349
>>> parser.parse_args('--foo XXX'.split())
13451350
Namespace(bar='XXX')
13461351

1352+
.. versionchanged:: next
1353+
Single-dash long option now takes precedence over short options.
1354+
13471355

13481356
.. _deprecated:
13491357

Doc/library/bdb.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ The :mod:`bdb` module also defines two classes:
236236
Normally derived classes don't override the following methods, but they may
237237
if they want to redefine the definition of stopping and breakpoints.
238238

239-
.. method:: is_skipped_line(module_name)
239+
.. method:: is_skipped_module(module_name)
240240

241241
Return ``True`` if *module_name* matches any skip pattern.
242242

Doc/whatsnew/3.15.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,3 +1279,10 @@ that may require changes to your code.
12791279
Use its :meth:`!close` method or the :func:`contextlib.closing` context
12801280
manager to close it.
12811281
(Contributed by Osama Abdelkader and Serhiy Storchaka in :gh:`140601`.)
1282+
1283+
* If a short option and a single-dash long option are passed to
1284+
:meth:`argparse.ArgumentParser.add_argument`, *dest* is now inferred from
1285+
the single-dash long option. For example, in ``add_argument('-f', '-foo')``,
1286+
*dest* is now ``'foo'`` instead of ``'f'``.
1287+
Pass an explicit *dest* argument to preserve the old behavior.
1288+
(Contributed by Serhiy Storchaka in :gh:`138697`.)

Include/internal/pycore_critical_section.h

Lines changed: 57 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ extern "C" {
3232
const bool _should_lock_cs = PyList_CheckExact(_orig_seq); \
3333
PyCriticalSection _cs; \
3434
if (_should_lock_cs) { \
35-
_PyCriticalSection_Begin(&_cs, _orig_seq); \
35+
PyCriticalSection_Begin(&_cs, _orig_seq); \
3636
}
3737

3838
# define Py_END_CRITICAL_SECTION_SEQUENCE_FAST() \
@@ -77,10 +77,10 @@ _PyCriticalSection_Resume(PyThreadState *tstate);
7777

7878
// (private) slow path for locking the mutex
7979
PyAPI_FUNC(void)
80-
_PyCriticalSection_BeginSlow(PyCriticalSection *c, PyMutex *m);
80+
_PyCriticalSection_BeginSlow(PyThreadState *tstate, PyCriticalSection *c, PyMutex *m);
8181

8282
PyAPI_FUNC(void)
83-
_PyCriticalSection2_BeginSlow(PyCriticalSection2 *c, PyMutex *m1, PyMutex *m2,
83+
_PyCriticalSection2_BeginSlow(PyThreadState *tstate, PyCriticalSection2 *c, PyMutex *m1, PyMutex *m2,
8484
int is_m1_locked);
8585

8686
PyAPI_FUNC(void)
@@ -95,34 +95,30 @@ _PyCriticalSection_IsActive(uintptr_t tag)
9595
}
9696

9797
static inline void
98-
_PyCriticalSection_BeginMutex(PyCriticalSection *c, PyMutex *m)
98+
_PyCriticalSection_BeginMutex(PyThreadState *tstate, PyCriticalSection *c, PyMutex *m)
9999
{
100100
if (PyMutex_LockFast(m)) {
101-
PyThreadState *tstate = _PyThreadState_GET();
102101
c->_cs_mutex = m;
103102
c->_cs_prev = tstate->critical_section;
104103
tstate->critical_section = (uintptr_t)c;
105104
}
106105
else {
107-
_PyCriticalSection_BeginSlow(c, m);
106+
_PyCriticalSection_BeginSlow(tstate, c, m);
108107
}
109108
}
110-
#define PyCriticalSection_BeginMutex _PyCriticalSection_BeginMutex
111109

112110
static inline void
113-
_PyCriticalSection_Begin(PyCriticalSection *c, PyObject *op)
111+
_PyCriticalSection_Begin(PyThreadState *tstate, PyCriticalSection *c, PyObject *op)
114112
{
115-
_PyCriticalSection_BeginMutex(c, &op->ob_mutex);
113+
_PyCriticalSection_BeginMutex(tstate, c, &op->ob_mutex);
116114
}
117-
#define PyCriticalSection_Begin _PyCriticalSection_Begin
118115

119116
// Removes the top-most critical section from the thread's stack of critical
120117
// sections. If the new top-most critical section is inactive, then it is
121118
// resumed.
122119
static inline void
123-
_PyCriticalSection_Pop(PyCriticalSection *c)
120+
_PyCriticalSection_Pop(PyThreadState *tstate, PyCriticalSection *c)
124121
{
125-
PyThreadState *tstate = _PyThreadState_GET();
126122
uintptr_t prev = c->_cs_prev;
127123
tstate->critical_section = prev;
128124

@@ -132,7 +128,7 @@ _PyCriticalSection_Pop(PyCriticalSection *c)
132128
}
133129

134130
static inline void
135-
_PyCriticalSection_End(PyCriticalSection *c)
131+
_PyCriticalSection_End(PyThreadState *tstate, PyCriticalSection *c)
136132
{
137133
// If the mutex is NULL, we used the fast path in
138134
// _PyCriticalSection_BeginSlow for locks already held in the top-most
@@ -141,18 +137,17 @@ _PyCriticalSection_End(PyCriticalSection *c)
141137
return;
142138
}
143139
PyMutex_Unlock(c->_cs_mutex);
144-
_PyCriticalSection_Pop(c);
140+
_PyCriticalSection_Pop(tstate, c);
145141
}
146-
#define PyCriticalSection_End _PyCriticalSection_End
147142

148143
static inline void
149-
_PyCriticalSection2_BeginMutex(PyCriticalSection2 *c, PyMutex *m1, PyMutex *m2)
144+
_PyCriticalSection2_BeginMutex(PyThreadState *tstate, PyCriticalSection2 *c, PyMutex *m1, PyMutex *m2)
150145
{
151146
if (m1 == m2) {
152147
// If the two mutex arguments are the same, treat this as a critical
153148
// section with a single mutex.
154149
c->_cs_mutex2 = NULL;
155-
_PyCriticalSection_BeginMutex(&c->_cs_base, m1);
150+
_PyCriticalSection_BeginMutex(tstate, &c->_cs_base, m1);
156151
return;
157152
}
158153

@@ -167,7 +162,6 @@ _PyCriticalSection2_BeginMutex(PyCriticalSection2 *c, PyMutex *m1, PyMutex *m2)
167162

168163
if (PyMutex_LockFast(m1)) {
169164
if (PyMutex_LockFast(m2)) {
170-
PyThreadState *tstate = _PyThreadState_GET();
171165
c->_cs_base._cs_mutex = m1;
172166
c->_cs_mutex2 = m2;
173167
c->_cs_base._cs_prev = tstate->critical_section;
@@ -176,24 +170,22 @@ _PyCriticalSection2_BeginMutex(PyCriticalSection2 *c, PyMutex *m1, PyMutex *m2)
176170
tstate->critical_section = p;
177171
}
178172
else {
179-
_PyCriticalSection2_BeginSlow(c, m1, m2, 1);
173+
_PyCriticalSection2_BeginSlow(tstate, c, m1, m2, 1);
180174
}
181175
}
182176
else {
183-
_PyCriticalSection2_BeginSlow(c, m1, m2, 0);
177+
_PyCriticalSection2_BeginSlow(tstate, c, m1, m2, 0);
184178
}
185179
}
186-
#define PyCriticalSection2_BeginMutex _PyCriticalSection2_BeginMutex
187180

188181
static inline void
189-
_PyCriticalSection2_Begin(PyCriticalSection2 *c, PyObject *a, PyObject *b)
182+
_PyCriticalSection2_Begin(PyThreadState *tstate, PyCriticalSection2 *c, PyObject *a, PyObject *b)
190183
{
191-
_PyCriticalSection2_BeginMutex(c, &a->ob_mutex, &b->ob_mutex);
184+
_PyCriticalSection2_BeginMutex(tstate, c, &a->ob_mutex, &b->ob_mutex);
192185
}
193-
#define PyCriticalSection2_Begin _PyCriticalSection2_Begin
194186

195187
static inline void
196-
_PyCriticalSection2_End(PyCriticalSection2 *c)
188+
_PyCriticalSection2_End(PyThreadState *tstate, PyCriticalSection2 *c)
197189
{
198190
// if mutex1 is NULL, we used the fast path in
199191
// _PyCriticalSection_BeginSlow for mutexes that are already held,
@@ -207,9 +199,8 @@ _PyCriticalSection2_End(PyCriticalSection2 *c)
207199
PyMutex_Unlock(c->_cs_mutex2);
208200
}
209201
PyMutex_Unlock(c->_cs_base._cs_mutex);
210-
_PyCriticalSection_Pop(&c->_cs_base);
202+
_PyCriticalSection_Pop(tstate, &c->_cs_base);
211203
}
212-
#define PyCriticalSection2_End _PyCriticalSection2_End
213204

214205
static inline void
215206
_PyCriticalSection_AssertHeld(PyMutex *mutex)
@@ -251,6 +242,45 @@ _PyCriticalSection_AssertHeldObj(PyObject *op)
251242

252243
#endif
253244
}
245+
246+
#undef Py_BEGIN_CRITICAL_SECTION
247+
# define Py_BEGIN_CRITICAL_SECTION(op) \
248+
{ \
249+
PyCriticalSection _py_cs; \
250+
PyThreadState *_cs_tstate = _PyThreadState_GET(); \
251+
_PyCriticalSection_Begin(_cs_tstate, &_py_cs, _PyObject_CAST(op))
252+
253+
#undef Py_BEGIN_CRITICAL_SECTION_MUTEX
254+
# define Py_BEGIN_CRITICAL_SECTION_MUTEX(mutex) \
255+
{ \
256+
PyCriticalSection _py_cs; \
257+
PyThreadState *_cs_tstate = _PyThreadState_GET(); \
258+
_PyCriticalSection_BeginMutex(_cs_tstate, &_py_cs, mutex)
259+
260+
#undef Py_END_CRITICAL_SECTION
261+
# define Py_END_CRITICAL_SECTION() \
262+
_PyCriticalSection_End(_cs_tstate, &_py_cs); \
263+
}
264+
265+
#undef Py_BEGIN_CRITICAL_SECTION2
266+
# define Py_BEGIN_CRITICAL_SECTION2(a, b) \
267+
{ \
268+
PyCriticalSection2 _py_cs2; \
269+
PyThreadState *_cs_tstate = _PyThreadState_GET(); \
270+
_PyCriticalSection2_Begin(_cs_tstate, &_py_cs2, _PyObject_CAST(a), _PyObject_CAST(b))
271+
272+
#undef Py_BEGIN_CRITICAL_SECTION2_MUTEX
273+
# define Py_BEGIN_CRITICAL_SECTION2_MUTEX(m1, m2) \
274+
{ \
275+
PyCriticalSection2 _py_cs2; \
276+
PyThreadState *_cs_tstate = _PyThreadState_GET(); \
277+
_PyCriticalSection2_BeginMutex(_cs_tstate, &_py_cs2, m1, m2)
278+
279+
#undef Py_END_CRITICAL_SECTION2
280+
# define Py_END_CRITICAL_SECTION2() \
281+
_PyCriticalSection2_End(_cs_tstate, &_py_cs2); \
282+
}
283+
254284
#endif /* Py_GIL_DISABLED */
255285

256286
#ifdef __cplusplus

0 commit comments

Comments
 (0)