Skip to content

Commit b366a06

Browse files
committed
Merge branch 'main' into inplace_add
2 parents 74ceb37 + 70945d5 commit b366a06

File tree

81 files changed

+633
-611
lines changed

Some content is hidden

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

81 files changed

+633
-611
lines changed

Doc/c-api/init.rst

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1173,6 +1173,26 @@ All of the following functions must be called after :c:func:`Py_Initialize`.
11731173
.. versionadded:: 3.9
11741174
11751175
1176+
.. c:function:: void PyThreadState_EnterTracing(PyThreadState *tstate)
1177+
1178+
Suspend tracing and profiling in the Python thread state *tstate*.
1179+
1180+
Resume them using the:c:func:`PyThreadState_LeaveTracing` function.
1181+
1182+
.. versionadded:: 3.11
1183+
1184+
1185+
.. c:function:: void PyThreadState_LeaveTracing(PyThreadState *tstate)
1186+
1187+
Resume tracing and profiling in the Python thread state *tstate* suspended
1188+
by the:c:func:`PyThreadState_EnterTracing` function.
1189+
1190+
See also :c:func:`PyEval_SetTrace` and :c:func:`PyEval_SetProfile`
1191+
functions.
1192+
1193+
.. versionadded:: 3.11
1194+
1195+
11761196
.. c:function:: PyInterpreterState* PyInterpreterState_Get(void)
11771197
11781198
Get the current interpreter.
@@ -1623,6 +1643,8 @@ Python-level trace functions in previous versions.
16231643
profile function is called for all monitored events except :const:`PyTrace_LINE`
16241644
:const:`PyTrace_OPCODE` and :const:`PyTrace_EXCEPTION`.
16251645
1646+
See also the :func:`sys.setprofile` function.
1647+
16261648
The caller must hold the :term:`GIL`.
16271649
16281650
@@ -1635,6 +1657,8 @@ Python-level trace functions in previous versions.
16351657
will not receive :const:`PyTrace_C_CALL`, :const:`PyTrace_C_EXCEPTION` or
16361658
:const:`PyTrace_C_RETURN` as a value for the *what* parameter.
16371659
1660+
See also the :func:`sys.settrace` function.
1661+
16381662
The caller must hold the :term:`GIL`.
16391663
16401664

Doc/faq/extending.rst

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -290,9 +290,6 @@ complete example using the GNU readline library (you may want to ignore
290290

291291
#define PY_SSIZE_T_CLEAN
292292
#include <Python.h>
293-
#include <object.h>
294-
#include <compile.h>
295-
#include <eval.h>
296293

297294
int main (int argc, char* argv[])
298295
{

Doc/faq/windows.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ Embedding the Python interpreter in a Windows app can be summarized as follows:
212212

213213
.. code-block:: c
214214
215-
#include "python.h"
215+
#include <Python.h>
216216
...
217217
Py_Initialize(); // Initialize Python.
218218
initmyAppc(); // Initialize (import) the helper class.

Doc/library/random.rst

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -135,15 +135,10 @@ Functions for integers
135135
values. Formerly it used a style like ``int(random()*n)`` which could produce
136136
slightly uneven distributions.
137137

138-
.. deprecated:: 3.10
139-
The automatic conversion of non-integer types to equivalent integers is
140-
deprecated. Currently ``randrange(10.0)`` is losslessly converted to
141-
``randrange(10)``. In the future, this will raise a :exc:`TypeError`.
142-
143-
.. deprecated:: 3.10
144-
The exception raised for non-integral values such as ``randrange(10.5)``
145-
or ``randrange('10')`` will be changed from :exc:`ValueError` to
146-
:exc:`TypeError`.
138+
.. versionchanged:: 3.11
139+
Automatic conversion of non-integer types is no longer supported.
140+
Calls such as ``randrange(10.0)`` and ``randrange(Fraction(10, 1))``
141+
now raise a :exc:`TypeError`.
147142

148143
.. function:: randint(a, b)
149144

@@ -508,7 +503,7 @@ between the effects of a drug versus a placebo::
508503

509504
Simulation of arrival times and service deliveries for a multiserver queue::
510505

511-
from heapq import heappush, heappop
506+
from heapq import heapify, heapreplace
512507
from random import expovariate, gauss
513508
from statistics import mean, quantiles
514509

@@ -520,14 +515,15 @@ Simulation of arrival times and service deliveries for a multiserver queue::
520515
waits = []
521516
arrival_time = 0.0
522517
servers = [0.0] * num_servers # time when each server becomes available
523-
for i in range(100_000):
518+
heapify(servers)
519+
for i in range(1_000_000):
524520
arrival_time += expovariate(1.0 / average_arrival_interval)
525-
next_server_available = heappop(servers)
521+
next_server_available = servers[0]
526522
wait = max(0.0, next_server_available - arrival_time)
527523
waits.append(wait)
528-
service_duration = gauss(average_service_time, stdev_service_time)
524+
service_duration = max(0.0, gauss(average_service_time, stdev_service_time))
529525
service_completed = arrival_time + wait + service_duration
530-
heappush(servers, service_completed)
526+
heapreplace(servers, service_completed)
531527

532528
print(f'Mean wait: {mean(waits):.1f} Max wait: {max(waits):.1f}')
533529
print('Quartiles:', [round(q, 1) for q in quantiles(waits)])

Doc/reference/executionmodel.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -119,14 +119,14 @@ is subtle. Python lacks declarations and allows name binding operations to
119119
occur anywhere within a code block. The local variables of a code block can be
120120
determined by scanning the entire text of the block for name binding operations.
121121

122-
If the :keyword:`global` statement occurs within a block, all uses of the name
123-
specified in the statement refer to the binding of that name in the top-level
122+
If the :keyword:`global` statement occurs within a block, all uses of the names
123+
specified in the statement refer to the bindings of those names in the top-level
124124
namespace. Names are resolved in the top-level namespace by searching the
125125
global namespace, i.e. the namespace of the module containing the code block,
126126
and the builtins namespace, the namespace of the module :mod:`builtins`. The
127-
global namespace is searched first. If the name is not found there, the
127+
global namespace is searched first. If the names are not found there, the
128128
builtins namespace is searched. The :keyword:`!global` statement must precede
129-
all uses of the name.
129+
all uses of the listed names.
130130

131131
The :keyword:`global` statement has the same scope as a name binding operation
132132
in the same block. If the nearest enclosing scope for a free variable contains

Doc/tutorial/venv.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ For example:
8888
'~/envs/tutorial-env/lib/python3.5/site-packages']
8989
>>>
9090
91+
To deactivate a virtual environment, type::
92+
93+
deactivate
94+
95+
into the terminal.
9196

9297
Managing Packages with pip
9398
==========================

Doc/using/cmdline.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,8 @@ Miscellaneous options
483483
* ``-X frozen_modules`` determines whether or not frozen modules are
484484
ignored by the import machinery. A value of "on" means they get
485485
imported and "off" means they are ignored. The default is "on"
486-
for non-debug builds (the normal case) and "off" for debug builds.
486+
if this is an installed Python (the normal case). If it's under
487+
development (running from the source tree) then the default is "off".
487488
Note that the "importlib_bootstrap" and "importlib_bootstrap_external"
488489
frozen modules are always used, even if this flag is set to "off".
489490

Doc/whatsnew/3.11.rst

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -261,12 +261,12 @@ time
261261
``nanosleep()`` function, if available, which has a resolution of 1 nanosecond
262262
(10\ :sup:`-9` seconds), rather than using ``select()`` which has a resolution
263263
of 1 microsecond (10\ :sup:`-6` seconds).
264-
(Contributed by Livius and Victor Stinner in :issue:`21302`.)
264+
(Contributed by Benjamin Szőke and Victor Stinner in :issue:`21302`.)
265265

266266
* On Windows, :func:`time.sleep` now uses a waitable timer which has a
267267
resolution of 100 nanoseconds (10\ :sup:`-7` seconds). Previously, it had
268268
a resolution of 1 millisecond (10\ :sup:`-3` seconds).
269-
(Contributed by Livius and Victor Stinner in :issue:`21302`.)
269+
(Contributed by Benjamin Szőke and Victor Stinner in :issue:`21302`.)
270270

271271
unicodedata
272272
-----------
@@ -461,7 +461,8 @@ Build Changes
461461
(Contributed by Mike Gilbert in :issue:`45433`.)
462462

463463
* Building Python now requires a C99 ``<math.h>`` header file providing
464-
``isinf()``, ``isnan()`` and ``isfinite()`` functions.
464+
the following functions: ``copysign()``, ``hypot()``, ``isfinite()``,
465+
``isinf()``, ``isnan()``, ``round()``.
465466
(Contributed by Victor Stinner in :issue:`45440`.)
466467

467468
C API Changes
@@ -476,6 +477,11 @@ New Features
476477
* Add a new :c:func:`PyType_GetQualName` function to get type's qualified name.
477478
(Contributed by Hai Shi in :issue:`42035`.)
478479

480+
* Add new :c:func:`PyThreadState_EnterTracing` and
481+
:c:func:`PyThreadState_LeaveTracing` functions to the limited C API to
482+
suspend and resume tracing and profiling.
483+
(Contributed by Victor Stinner in :issue:`43760`.)
484+
479485
Porting to Python 3.11
480486
----------------------
481487

@@ -572,23 +578,17 @@ Porting to Python 3.11
572578
header provides functions like ``printf()`` and ``fopen()``.
573579
(Contributed by Victor Stinner in :issue:`45434`.)
574580

575-
* The non-limited API files ``cellobject.h`` and ``funcobject.h`` have been
576-
moved to the ``Include/cpython`` directory. These files must not be included
577-
directly, as they are already included in ``Python.h``: :ref:`Include Files
578-
<api-includes>`. If they have been included directly, consider including
579-
``Python.h`` instead.
581+
* The non-limited API files ``cellobject.h``, ``classobject.h``, ``context.h``,
582+
``funcobject.h``, ``genobject.h`` and ``longintrepr.h`` have been moved to
583+
the ``Include/cpython`` directory. Moreover, the ``eval.h`` header file was
584+
removed. These files must not be included directly, as they are already
585+
included in ``Python.h``: :ref:`Include Files <api-includes>`. If they have
586+
been included directly, consider including ``Python.h`` instead.
580587
(Contributed by Victor Stinner in :issue:`35134`.)
581588

582589
Deprecated
583590
----------
584591

585-
Removed
586-
-------
587-
588-
* :c:func:`PyFrame_BlockSetup` and :c:func:`PyFrame_BlockPop` have been
589-
removed.
590-
(Contributed by Mark Shannon in :issue:`40222`.)
591-
592592
* Deprecate the following functions to configure the Python initialization:
593593

594594
* :c:func:`PySys_AddWarnOptionUnicode`
@@ -605,6 +605,13 @@ Removed
605605
<init-config>` instead (:pep:`587`).
606606
(Contributed by Victor Stinner in :issue:`44113`.)
607607

608+
Removed
609+
-------
610+
611+
* :c:func:`PyFrame_BlockSetup` and :c:func:`PyFrame_BlockPop` have been
612+
removed.
613+
(Contributed by Mark Shannon in :issue:`40222`.)
614+
608615
* Remove the following math macros using the ``errno`` variable:
609616

610617
* ``Py_ADJUST_ERANGE1()``

Include/Python.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
#include "bytesobject.h"
4747
#include "unicodeobject.h"
4848
#include "longobject.h"
49-
#include "longintrepr.h"
49+
#include "cpython/longintrepr.h"
5050
#include "boolobject.h"
5151
#include "floatobject.h"
5252
#include "complexobject.h"
@@ -61,7 +61,7 @@
6161
#include "methodobject.h"
6262
#include "moduleobject.h"
6363
#include "cpython/funcobject.h"
64-
#include "classobject.h"
64+
#include "cpython/classobject.h"
6565
#include "fileobject.h"
6666
#include "pycapsule.h"
6767
#include "code.h"
@@ -70,21 +70,20 @@
7070
#include "sliceobject.h"
7171
#include "cpython/cellobject.h"
7272
#include "iterobject.h"
73-
#include "genobject.h"
73+
#include "pystate.h"
74+
#include "cpython/genobject.h"
7475
#include "descrobject.h"
7576
#include "genericaliasobject.h"
7677
#include "warnings.h"
7778
#include "weakrefobject.h"
7879
#include "structseq.h"
79-
#include "namespaceobject.h"
8080
#include "cpython/picklebufobject.h"
8181
#include "cpython/pytime.h"
8282
#include "codecs.h"
8383
#include "pyerrors.h"
8484
#include "cpython/initconfig.h"
8585
#include "pythread.h"
86-
#include "pystate.h"
87-
#include "context.h"
86+
#include "cpython/context.h"
8887
#include "modsupport.h"
8988
#include "compile.h"
9089
#include "pythonrun.h"
@@ -96,7 +95,6 @@
9695
#include "import.h"
9796
#include "abstract.h"
9897
#include "bltinmodule.h"
99-
#include "eval.h"
10098
#include "cpython/pyctype.h"
10199
#include "pystrtod.h"
102100
#include "pystrcmp.h"

Include/ceval.h

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,21 @@
1+
/* Interface to random parts in ceval.c */
2+
13
#ifndef Py_CEVAL_H
24
#define Py_CEVAL_H
35
#ifdef __cplusplus
46
extern "C" {
57
#endif
68

79

8-
/* Interface to random parts in ceval.c */
10+
PyAPI_FUNC(PyObject *) PyEval_EvalCode(PyObject *, PyObject *, PyObject *);
11+
12+
PyAPI_FUNC(PyObject *) PyEval_EvalCodeEx(PyObject *co,
13+
PyObject *globals,
14+
PyObject *locals,
15+
PyObject *const *args, int argc,
16+
PyObject *const *kwds, int kwdc,
17+
PyObject *const *defs, int defc,
18+
PyObject *kwdefs, PyObject *closure);
919

1020
/* PyEval_CallObjectWithKeywords(), PyEval_CallObject(), PyEval_CallFunction
1121
* and PyEval_CallMethod are deprecated. Since they are officially part of the

Include/cpython/ceval.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
# error "this header file must not be included directly"
33
#endif
44

5+
PyAPI_FUNC(PyObject *) _PyEval_CallTracing(PyObject *func, PyObject *args);
6+
57
PyAPI_FUNC(void) PyEval_SetProfile(Py_tracefunc, PyObject *);
68
PyAPI_DATA(int) _PyEval_SetProfile(PyThreadState *tstate, Py_tracefunc func, PyObject *arg);
79
PyAPI_FUNC(void) PyEval_SetTrace(Py_tracefunc, PyObject *);

Include/classobject.h renamed to Include/cpython/classobject.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,5 +53,5 @@ PyAPI_FUNC(PyObject *) PyInstanceMethod_Function(PyObject *);
5353
#ifdef __cplusplus
5454
}
5555
#endif
56-
#endif /* !Py_CLASSOBJECT_H */
57-
#endif /* Py_LIMITED_API */
56+
#endif // !Py_CLASSOBJECT_H
57+
#endif // !Py_LIMITED_API

Include/context.h renamed to Include/cpython/context.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1+
#ifndef Py_LIMITED_API
12
#ifndef Py_CONTEXT_H
23
#define Py_CONTEXT_H
34
#ifdef __cplusplus
45
extern "C" {
56
#endif
67

7-
#ifndef Py_LIMITED_API
8-
9-
108
PyAPI_DATA(PyTypeObject) PyContext_Type;
119
typedef struct _pycontextobject PyContext;
1210

@@ -73,9 +71,8 @@ PyAPI_FUNC(int) PyContextVar_Reset(PyObject *var, PyObject *token);
7371
PyAPI_FUNC(PyObject *) _PyContext_NewHamtForTests(void);
7472

7573

76-
#endif /* !Py_LIMITED_API */
77-
7874
#ifdef __cplusplus
7975
}
8076
#endif
8177
#endif /* !Py_CONTEXT_H */
78+
#endif /* !Py_LIMITED_API */

Include/genobject.h renamed to Include/cpython/genobject.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
/* Generator object interface */
32

43
#ifndef Py_LIMITED_API
@@ -8,8 +7,7 @@
87
extern "C" {
98
#endif
109

11-
#include "pystate.h" /* _PyErr_StackItem */
12-
#include "abstract.h" /* PySendResult */
10+
/* --- Generators --------------------------------------------------------- */
1311

1412
/* _PyGenObject_HEAD defines the initial segment of generator
1513
and coroutine objects. */
@@ -45,7 +43,9 @@ PyAPI_FUNC(int) _PyGen_FetchStopIterationValue(PyObject **);
4543
PyObject *_PyGen_yf(PyGenObject *);
4644
PyAPI_FUNC(void) _PyGen_Finalize(PyObject *self);
4745

48-
#ifndef Py_LIMITED_API
46+
47+
/* --- PyCoroObject ------------------------------------------------------- */
48+
4949
typedef struct {
5050
_PyGenObject_HEAD(cr)
5151
PyObject *cr_origin;
@@ -59,7 +59,8 @@ PyObject *_PyCoro_GetAwaitableIter(PyObject *o);
5959
PyAPI_FUNC(PyObject *) PyCoro_New(PyFrameObject *,
6060
PyObject *name, PyObject *qualname);
6161

62-
/* Asynchronous Generators */
62+
63+
/* --- Asynchronous Generators -------------------------------------------- */
6364

6465
typedef struct {
6566
_PyGenObject_HEAD(ag)
@@ -89,7 +90,6 @@ PyAPI_FUNC(PyObject *) PyAsyncGen_New(PyFrameObject *,
8990

9091
PyObject *_PyAsyncGenValueWrapperNew(PyObject *);
9192

92-
#endif
9393

9494
#undef _PyGenObject_HEAD
9595

File renamed without changes.

0 commit comments

Comments
 (0)