Skip to content

Commit 136729d

Browse files
committed
Merge branch 'main' into pythongh-127274-method-flag
2 parents 4de9ebd + 1b15c89 commit 136729d

File tree

121 files changed

+2463
-1124
lines changed

Some content is hidden

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

121 files changed

+2463
-1124
lines changed

.github/workflows/reusable-macos.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242
run: |
4343
brew install pkg-config [email protected] xz gdbm tcl-tk@8 make
4444
# Because alternate versions are not symlinked into place by default:
45-
brew link tcl-tk@8
45+
brew link --overwrite tcl-tk@8
4646
- name: Configure CPython
4747
run: |
4848
GDBM_CFLAGS="-I$(brew --prefix gdbm)/include" \

Doc/c-api/monitoring.rst

+9-3
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,14 @@ See :mod:`sys.monitoring` for descriptions of the events.
7575
Fire a ``JUMP`` event.
7676
7777
78-
.. c:function:: int PyMonitoring_FireBranchEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, PyObject *target_offset)
78+
.. c:function:: int PyMonitoring_FireBranchLeftEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, PyObject *target_offset)
7979
80-
Fire a ``BRANCH`` event.
80+
Fire a ``BRANCH_LEFT`` event.
81+
82+
83+
.. c:function:: int PyMonitoring_FireBranchRightEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, PyObject *target_offset)
84+
85+
Fire a ``BRANCH_RIGHT`` event.
8186
8287
8388
.. c:function:: int PyMonitoring_FireCReturnEvent(PyMonitoringState *state, PyObject *codelike, int32_t offset, PyObject *retval)
@@ -168,7 +173,8 @@ would typically correspond to a python function.
168173
================================================== =====================================
169174
Macro Event
170175
================================================== =====================================
171-
.. c:macro:: PY_MONITORING_EVENT_BRANCH :monitoring-event:`BRANCH`
176+
.. c:macro:: PY_MONITORING_EVENT_BRANCH_LEFT :monitoring-event:`BRANCH_LEFT`
177+
.. c:macro:: PY_MONITORING_EVENT_BRANCH_RIGHT :monitoring-event:`BRANCH_RIGHT`
172178
.. c:macro:: PY_MONITORING_EVENT_CALL :monitoring-event:`CALL`
173179
.. c:macro:: PY_MONITORING_EVENT_C_RAISE :monitoring-event:`C_RAISE`
174180
.. c:macro:: PY_MONITORING_EVENT_C_RETURN :monitoring-event:`C_RETURN`

Doc/c-api/weakref.rst

+9
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,15 @@ as much as it can.
8888
Use :c:func:`PyWeakref_GetRef` instead.
8989
9090
91+
.. c:function:: int PyWeakref_IsDead(PyObject *ref)
92+
93+
Test if the weak reference *ref* is dead. Returns 1 if the reference is
94+
dead, 0 if it is alive, and -1 with an error set if *ref* is not a weak
95+
reference object.
96+
97+
.. versionadded:: 3.14
98+
99+
91100
.. c:function:: void PyObject_ClearWeakRefs(PyObject *object)
92101
93102
This function is called by the :c:member:`~PyTypeObject.tp_dealloc` handler

Doc/library/asyncio-policy.rst

+8
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,20 @@ for the current process:
4040

4141
Return the current process-wide policy.
4242

43+
.. deprecated:: next
44+
The :func:`get_event_loop_policy` function is deprecated and
45+
will be removed in Python 3.16.
46+
4347
.. function:: set_event_loop_policy(policy)
4448

4549
Set the current process-wide policy to *policy*.
4650

4751
If *policy* is set to ``None``, the default policy is restored.
4852

53+
.. deprecated:: next
54+
The :func:`set_event_loop_policy` function is deprecated and
55+
will be removed in Python 3.16.
56+
4957

5058
.. _asyncio-policy-objects:
5159

Doc/library/os.rst

+12
Original file line numberDiff line numberDiff line change
@@ -5420,10 +5420,22 @@ operating system.
54205420
Scheduling policy for CPU-intensive processes that tries to preserve
54215421
interactivity on the rest of the computer.
54225422

5423+
.. data:: SCHED_DEADLINE
5424+
5425+
Scheduling policy for tasks with deadline constraints.
5426+
5427+
.. versionadded:: next
5428+
54235429
.. data:: SCHED_IDLE
54245430

54255431
Scheduling policy for extremely low priority background tasks.
54265432

5433+
.. data:: SCHED_NORMAL
5434+
5435+
Alias for :data:`SCHED_OTHER`.
5436+
5437+
.. versionadded:: next
5438+
54275439
.. data:: SCHED_SPORADIC
54285440

54295441
Scheduling policy for sporadic server programs.

Doc/library/ssl.rst

+2-2
Original file line numberDiff line numberDiff line change
@@ -2508,8 +2508,8 @@ thus several things you need to be aware of:
25082508
.. seealso::
25092509

25102510
The :mod:`asyncio` module supports :ref:`non-blocking SSL sockets
2511-
<ssl-nonblocking>` and provides a
2512-
higher level API. It polls for events using the :mod:`selectors` module and
2511+
<ssl-nonblocking>` and provides a higher level :ref:`Streams API <asyncio-streams>`.
2512+
It polls for events using the :mod:`selectors` module and
25132513
handles :exc:`SSLWantWriteError`, :exc:`SSLWantReadError` and
25142514
:exc:`BlockingIOError` exceptions. It runs the SSL handshake asynchronously
25152515
as well.

Doc/library/sys.monitoring.rst

+23-6
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,17 @@ Events
7979

8080
The following events are supported:
8181

82-
.. monitoring-event:: BRANCH
82+
.. monitoring-event:: BRANCH_LEFT
8383

84-
A conditional branch is taken (or not).
84+
A conditional branch goes left.
85+
86+
It is up to the tool to determine how to present "left" and "right" branches.
87+
There is no guarantee which branch is "left" and which is "right", except
88+
that it will be consistent for the duration of the program.
89+
90+
.. monitoring-event:: BRANCH_RIGHT
91+
92+
A conditional branch goes right.
8593

8694
.. monitoring-event:: CALL
8795

@@ -180,9 +188,20 @@ The local events are:
180188
* :monitoring-event:`LINE`
181189
* :monitoring-event:`INSTRUCTION`
182190
* :monitoring-event:`JUMP`
183-
* :monitoring-event:`BRANCH`
191+
* :monitoring-event:`BRANCH_LEFT`
192+
* :monitoring-event:`BRANCH_RIGHT`
184193
* :monitoring-event:`STOP_ITERATION`
185194

195+
Deprecated event
196+
''''''''''''''''
197+
198+
* ``BRANCH``
199+
200+
The ``BRANCH`` event is deprecated in 3.14.
201+
Using :monitoring-event:`BRANCH_LEFT` and :monitoring-event:`BRANCH_RIGHT`
202+
events will give much better performance as they can be disabled
203+
independently.
204+
186205
Ancillary events
187206
''''''''''''''''
188207

@@ -357,13 +376,11 @@ Different events will provide the callback function with different arguments, as
357376

358377
func(code: CodeType, line_number: int) -> DISABLE | Any
359378

360-
* :monitoring-event:`BRANCH` and :monitoring-event:`JUMP`::
379+
* :monitoring-event:`BRANCH_LEFT`, :monitoring-event:`BRANCH_RIGHT` and :monitoring-event:`JUMP`::
361380

362381
func(code: CodeType, instruction_offset: int, destination_offset: int) -> DISABLE | Any
363382

364383
Note that the *destination_offset* is where the code will next execute.
365-
For an untaken branch this will be the offset of the instruction following
366-
the branch.
367384

368385
* :monitoring-event:`INSTRUCTION`::
369386

Doc/whatsnew/3.13.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -1971,7 +1971,7 @@ New Features
19711971
* :c:func:`PyMonitoring_FireCallEvent`
19721972
* :c:func:`PyMonitoring_FireLineEvent`
19731973
* :c:func:`PyMonitoring_FireJumpEvent`
1974-
* :c:func:`PyMonitoring_FireBranchEvent`
1974+
* ``PyMonitoring_FireBranchEvent``
19751975
* :c:func:`PyMonitoring_FireCReturnEvent`
19761976
* :c:func:`PyMonitoring_FirePyThrowEvent`
19771977
* :c:func:`PyMonitoring_FireRaiseEvent`

Doc/whatsnew/3.14.rst

+108
Original file line numberDiff line numberDiff line change
@@ -525,6 +525,10 @@ os
525525
same process.
526526
(Contributed by Victor Stinner in :gh:`120057`.)
527527

528+
* Add the :data:`~os.SCHED_DEADLINE` and :data:`~os.SCHED_NORMAL` constants
529+
to the :mod:`os` module.
530+
(Contributed by James Roy in :gh:`127688`.)
531+
528532

529533
pathlib
530534
-------
@@ -599,6 +603,11 @@ sys
599603
which only exists in specialized builds of Python, may now return objects
600604
from other interpreters than the one it's called in.
601605

606+
sys.monitoring
607+
--------------
608+
609+
Two new events are added: :monitoring-event:`BRANCH_LEFT` and
610+
:monitoring-event:`BRANCH_RIGHT`. The ``BRANCH`` event is deprecated.
602611

603612
tkinter
604613
-------
@@ -780,6 +789,96 @@ asyncio
780789
It now raises a :exc:`RuntimeError` if there is no current event loop.
781790
(Contributed by Kumar Aditya in :gh:`126353`.)
782791

792+
There's a few patterns that use :func:`asyncio.get_event_loop`, most
793+
of them can be replaced with :func:`asyncio.run`.
794+
795+
If you're running an async function, simply use :func:`asyncio.run`.
796+
797+
Before::
798+
799+
async def main():
800+
...
801+
802+
803+
loop = asyncio.get_event_loop()
804+
try:
805+
loop.run_until_complete(main())
806+
finally:
807+
loop.close()
808+
809+
After::
810+
811+
async def main():
812+
...
813+
814+
asyncio.run(main())
815+
816+
If you need to start something, e.g. a server listening on a socket
817+
and then run forever, use :func:`asyncio.run` and an
818+
:class:`asyncio.Event`.
819+
820+
Before::
821+
822+
def start_server(loop):
823+
...
824+
825+
loop = asyncio.get_event_loop()
826+
try:
827+
start_server(loop)
828+
loop.run_forever()
829+
finally:
830+
loop.close()
831+
832+
After::
833+
834+
def start_server(loop):
835+
...
836+
837+
async def main():
838+
start_server(asyncio.get_running_loop())
839+
await asyncio.Event().wait()
840+
841+
asyncio.run(main())
842+
843+
If you need to run something in an event loop, then run some blocking
844+
code around it, use :class:`asyncio.Runner`.
845+
846+
Before::
847+
848+
async def operation_one():
849+
...
850+
851+
def blocking_code():
852+
...
853+
854+
async def operation_two():
855+
...
856+
857+
loop = asyncio.get_event_loop()
858+
try:
859+
loop.run_until_complete(operation_one())
860+
blocking_code()
861+
loop.run_until_complete(operation_two())
862+
finally:
863+
loop.close()
864+
865+
After::
866+
867+
async def operation_one():
868+
...
869+
870+
def blocking_code():
871+
...
872+
873+
async def operation_two():
874+
...
875+
876+
with asyncio.Runner() as runner:
877+
runner.run(operation_one())
878+
blocking_code()
879+
runner.run(operation_two())
880+
881+
783882

784883
collections.abc
785884
---------------
@@ -1050,6 +1149,11 @@ New features
10501149
a :exc:`UnicodeError` object.
10511150
(Contributed by Bénédikt Tran in :gh:`127691`.)
10521151

1152+
* Add :c:func:`PyMonitoring_FireBranchLeftEvent` and
1153+
:c:func:`PyMonitoring_FireBranchRightEvent` for generating
1154+
:monitoring-event:`BRANCH_LEFT` and :monitoring-event:`BRANCH_RIGHT`
1155+
events, respectively.
1156+
10531157

10541158
Porting to Python 3.14
10551159
----------------------
@@ -1083,6 +1187,10 @@ Deprecated
10831187

10841188
.. include:: ../deprecations/c-api-pending-removal-in-future.rst
10851189

1190+
* The ``PyMonitoring_FireBranchEvent`` function is deprecated and should
1191+
be replaced with calls to :c:func:`PyMonitoring_FireBranchLeftEvent`
1192+
and :c:func:`PyMonitoring_FireBranchRightEvent`.
1193+
10861194
Removed
10871195
-------
10881196

Include/cpython/code.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@ extern "C" {
1111
/* Total tool ids available */
1212
#define _PY_MONITORING_TOOL_IDS 8
1313
/* Count of all local monitoring events */
14-
#define _PY_MONITORING_LOCAL_EVENTS 10
14+
#define _PY_MONITORING_LOCAL_EVENTS 11
1515
/* Count of all "real" monitoring events (not derived from other events) */
16-
#define _PY_MONITORING_UNGROUPED_EVENTS 15
16+
#define _PY_MONITORING_UNGROUPED_EVENTS 16
1717
/* Count of all monitoring events */
18-
#define _PY_MONITORING_EVENTS 17
18+
#define _PY_MONITORING_EVENTS 19
1919

2020
/* Tables of which tools are active for each monitored event. */
2121
typedef struct _Py_LocalMonitors {

0 commit comments

Comments
 (0)