Skip to content

Commit 20a73ed

Browse files
authored
Merge branch 'main' into bpo-46227/add-pathlib.Path.walk-method
2 parents 4509797 + 39c29f7 commit 20a73ed

130 files changed

Lines changed: 2235 additions & 1448 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.

.github/workflows/build_msi.yml

Lines changed: 8 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,48 +5,27 @@ on:
55
push:
66
branches:
77
- 'main'
8-
- '3.11'
9-
- '3.10'
10-
- '3.9'
11-
- '3.8'
12-
- '3.7'
8+
- '3.*'
139
paths:
1410
- 'Tools/msi/**'
1511
pull_request:
1612
branches:
1713
- 'main'
18-
- '3.11'
19-
- '3.10'
20-
- '3.9'
21-
- '3.8'
22-
- '3.7'
14+
- '3.*'
2315
paths:
2416
- 'Tools/msi/**'
2517

2618
permissions:
2719
contents: read
2820

2921
jobs:
30-
build_win32:
31-
name: 'Windows (x86) Installer'
22+
build:
23+
name: Windows Installer
3224
runs-on: windows-latest
25+
strategy:
26+
matrix:
27+
type: [x86, x64, arm64]
3328
steps:
3429
- uses: actions/checkout@v3
3530
- name: Build CPython installer
36-
run: .\Tools\msi\build.bat -x86
37-
38-
build_win_amd64:
39-
name: 'Windows (x64) Installer'
40-
runs-on: windows-latest
41-
steps:
42-
- uses: actions/checkout@v3
43-
- name: Build CPython installer
44-
run: .\Tools\msi\build.bat -x64
45-
46-
build_win_arm64:
47-
name: 'Windows (ARM64) Installer'
48-
runs-on: windows-latest
49-
steps:
50-
- uses: actions/checkout@v3
51-
- name: Build CPython installer
52-
run: .\Tools\msi\build.bat -arm64
31+
run: .\Tools\msi\build.bat -${{ matrix.type }}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: Update GH projects
2+
3+
on:
4+
issues:
5+
types:
6+
- opened
7+
- labeled
8+
9+
jobs:
10+
add-to-project:
11+
name: Add to the Release and Deferred Blocker project
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/add-to-project@v0.1.0
15+
with:
16+
project-url: https://github.com/orgs/python/projects/2
17+
github-token: ${{ secrets.ADD_TO_PROJECT_PAT }}
18+
labeled: release-blocker, deferred-blocker
19+
label-operator: OR

Doc/library/asyncio-task.rst

Lines changed: 102 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,29 @@ To actually run a coroutine, asyncio provides three main mechanisms:
103103
world
104104
finished at 17:14:34
105105

106+
* The :class:`asyncio.TaskGroup` class provides a more modern
107+
alternative to :func:`create_task`.
108+
Using this API, the last example becomes::
109+
110+
async def main():
111+
async with asyncio.TaskGroup() as tg:
112+
task1 = tg.create_task(
113+
say_after(1, 'hello'))
114+
115+
task2 = tg.create_task(
116+
say_after(2, 'world'))
117+
118+
print(f"started at {time.strftime('%X')}")
119+
120+
# The wait is implicit when the context manager exits.
121+
122+
print(f"finished at {time.strftime('%X')}")
123+
124+
The timing and output should be the same as for the previous version.
125+
126+
.. versionadded:: 3.11
127+
:class:`asyncio.TaskGroup`.
128+
106129

107130
.. _asyncio-awaitables:
108131

@@ -223,6 +246,11 @@ Creating Tasks
223246
:exc:`RuntimeError` is raised if there is no running loop in
224247
current thread.
225248

249+
.. note::
250+
251+
:meth:`asyncio.TaskGroup.create_task` is a newer alternative
252+
that allows for convenient waiting for a group of related tasks.
253+
226254
.. important::
227255

228256
Save a reference to the result of this function, to avoid
@@ -254,6 +282,77 @@ Creating Tasks
254282
Added the *context* parameter.
255283

256284

285+
Task Groups
286+
===========
287+
288+
Task groups combine a task creation API with a convenient
289+
and reliable way to wait for all tasks in the group to finish.
290+
291+
.. class:: TaskGroup()
292+
293+
An :ref:`asynchronous context manager <async-context-managers>`
294+
holding a group of tasks.
295+
Tasks can be added to the group using :meth:`create_task`.
296+
All tasks are awaited when the context manager exits.
297+
298+
.. versionadded:: 3.11
299+
300+
.. method:: create_task(coro, *, name=None, context=None)
301+
302+
Create a task in this task group.
303+
The signature matches that of :func:`asyncio.create_task`.
304+
305+
Example::
306+
307+
async def main():
308+
async with asyncio.TaskGroup() as tg:
309+
task1 = tg.create_task(some_coro(...))
310+
task2 = tg.create_task(another_coro(...))
311+
print("Both tasks have completed now.")
312+
313+
The ``async with`` statement will wait for all tasks in the group to finish.
314+
While waiting, new tasks may still be added to the group
315+
(for example, by passing ``tg`` into one of the coroutines
316+
and calling ``tg.create_task()`` in that coroutine).
317+
Once the last task has finished and the ``async with`` block is exited,
318+
no new tasks may be added to the group.
319+
320+
The first time any of the tasks belonging to the group fails
321+
with an exception other than :exc:`asyncio.CancelledError`,
322+
the remaining tasks in the group are cancelled.
323+
No further tasks can then be added to the group.
324+
At this point, if the body of the ``async with`` statement is still active
325+
(i.e., :meth:`~object.__aexit__` hasn't been called yet),
326+
the task directly containing the ``async with`` statement is also cancelled.
327+
The resulting :exc:`asyncio.CancelledError` will interrupt an ``await``,
328+
but it will not bubble out of the containing ``async with`` statement.
329+
330+
Once all tasks have finished, if any tasks have failed
331+
with an exception other than :exc:`asyncio.CancelledError`,
332+
those exceptions are combined in an
333+
:exc:`ExceptionGroup` or :exc:`BaseExceptionGroup`
334+
(as appropriate; see their documentation)
335+
which is then raised.
336+
337+
Two base exceptions are treated specially:
338+
If any task fails with :exc:`KeyboardInterrupt` or :exc:`SystemExit`,
339+
the task group still cancels the remaining tasks and waits for them,
340+
but then the initial :exc:`KeyboardInterrupt` or :exc:`SystemExit`
341+
is re-raised instead of :exc:`ExceptionGroup` or :exc:`BaseExceptionGroup`.
342+
343+
If the body of the ``async with`` statement exits with an exception
344+
(so :meth:`~object.__aexit__` is called with an exception set),
345+
this is treated the same as if one of the tasks failed:
346+
the remaining tasks are cancelled and then waited for,
347+
and non-cancellation exceptions are grouped into an
348+
exception group and raised.
349+
The exception passed into :meth:`~object.__aexit__`,
350+
unless it is :exc:`asyncio.CancelledError`,
351+
is also included in the exception group.
352+
The same special case is made for
353+
:exc:`KeyboardInterrupt` and :exc:`SystemExit` as in the previous paragraph.
354+
355+
257356
Sleeping
258357
========
259358

@@ -327,8 +426,9 @@ Running Tasks Concurrently
327426
cancellation of one submitted Task/Future to cause other
328427
Tasks/Futures to be cancelled.
329428

330-
.. versionchanged:: 3.10
331-
Removed the *loop* parameter.
429+
.. note::
430+
A more modern way to create and run tasks concurrently and
431+
wait for their completion is :class:`asyncio.TaskGroup`.
332432

333433
.. _asyncio_example_gather:
334434

Doc/library/dis.rst

Lines changed: 107 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -266,15 +266,17 @@ operation is being performed, so the intermediate analysis object isn't useful:
266266

267267
.. function:: findlinestarts(code)
268268

269-
This generator function uses the ``co_firstlineno`` and ``co_lnotab``
270-
attributes of the code object *code* to find the offsets which are starts of
269+
This generator function uses the ``co_lines`` method
270+
of the code object *code* to find the offsets which are starts of
271271
lines in the source code. They are generated as ``(offset, lineno)`` pairs.
272-
See :source:`Objects/lnotab_notes.txt` for the ``co_lnotab`` format and
273-
how to decode it.
274272

275273
.. versionchanged:: 3.6
276274
Line numbers can be decreasing. Before, they were always increasing.
277275

276+
.. versionchanged:: 3.10
277+
The :pep:`626` ``co_lines`` method is used instead of the ``co_firstlineno``
278+
and ``co_lnotab`` attributes of the code object.
279+
278280

279281
.. function:: findlabels(code)
280282

@@ -446,12 +448,13 @@ result back on the stack.
446448

447449
**Binary and in-place operations**
448450

449-
Binary operations remove the top of the stack (TOS) and the second top-most
450-
stack item (TOS1) from the stack. They perform the operation, and put the
451-
result back on the stack.
451+
In the following, TOS is the top-of-stack.
452+
TOS1, TOS2, TOS3 are the second, thrid and fourth items on the stack, respectively.
452453

453-
In-place operations are like binary operations, in that they remove TOS and
454-
TOS1, and push the result back on the stack, but the operation is done in-place
454+
Binary operations remove the top two items from the stack (TOS and TOS1).
455+
They perform the operation, then put the result back on the stack.
456+
457+
In-place operations are like binary operations, but the operation is done in-place
455458
when TOS1 supports it, and the resulting TOS may be (but does not have to be)
456459
the original TOS1.
457460

@@ -460,6 +463,7 @@ the original TOS1.
460463

461464
Implements the binary and in-place operators (depending on the value of
462465
*op*).
466+
``TOS = TOS1 op TOS``.
463467

464468
.. versionadded:: 3.11
465469

@@ -479,6 +483,20 @@ the original TOS1.
479483
Implements ``del TOS1[TOS]``.
480484

481485

486+
.. opcode:: BINARY_SLICE
487+
488+
Implements ``TOS = TOS2[TOS1:TOS]``.
489+
490+
.. versionadded:: 3.12
491+
492+
493+
.. opcode:: STORE_SLICE
494+
495+
Implements ``TOS2[TOS1:TOS] = TOS3``.
496+
497+
.. versionadded:: 3.12
498+
499+
482500
**Coroutine opcodes**
483501

484502
.. opcode:: GET_AWAITABLE (where)
@@ -1333,13 +1351,74 @@ iterations of the loop.
13331351
.. opcode:: HAVE_ARGUMENT
13341352

13351353
This is not really an opcode. It identifies the dividing line between
1336-
opcodes which don't use their argument and those that do
1337-
(``< HAVE_ARGUMENT`` and ``>= HAVE_ARGUMENT``, respectively).
1354+
opcodes in the range [0,255] which don't use their argument and those
1355+
that do (``< HAVE_ARGUMENT`` and ``>= HAVE_ARGUMENT``, respectively).
1356+
1357+
If your application uses pseudo instructions, use the :data:`hasarg`
1358+
collection instead.
13381359

13391360
.. versionchanged:: 3.6
13401361
Now every instruction has an argument, but opcodes ``< HAVE_ARGUMENT``
13411362
ignore it. Before, only opcodes ``>= HAVE_ARGUMENT`` had an argument.
13421363

1364+
.. versionchanged:: 3.12
1365+
Pseudo instructions were added to the :mod:`dis` module, and for them
1366+
it is not true that comparison with ``HAVE_ARGUMENT`` indicates whether
1367+
they use their arg.
1368+
1369+
1370+
**Pseudo-instructions**
1371+
1372+
These opcodes do not appear in python bytecode, they are used by the compiler
1373+
but are replaced by real opcodes or removed before bytecode is generated.
1374+
1375+
.. opcode:: SETUP_FINALLY (target)
1376+
1377+
Set up an exception handler for the following code block. If an exception
1378+
occurs, the value stack level is restored to its current state and control
1379+
is transferred to the exception handler at ``target``.
1380+
1381+
1382+
.. opcode:: SETUP_CLEANUP (target)
1383+
1384+
Like ``SETUP_FINALLY``, but in case of exception also pushes the last
1385+
instruction (``lasti``) to the stack so that ``RERAISE`` can restore it.
1386+
If an exception occurs, the value stack level and the last instruction on
1387+
the frame are restored to their current state, and control is transferred
1388+
to the exception handler at ``target``.
1389+
1390+
1391+
.. opcode:: SETUP_WITH (target)
1392+
1393+
Like ``SETUP_CLEANUP``, but in case of exception one more item is popped
1394+
from the stack before control is transferred to the exception handler at
1395+
``target``.
1396+
1397+
This variant is used in :keyword:`with` and :keyword:`async with`
1398+
constructs, which push the return value of the context manager's
1399+
:meth:`~object.__enter__` or :meth:`~object.__aenter__` to the stack.
1400+
1401+
1402+
.. opcode:: POP_BLOCK
1403+
1404+
Marks the end of the code block associated with the last ``SETUP_FINALLY``,
1405+
``SETUP_CLEANUP`` or ``SETUP_WITH``.
1406+
1407+
.. opcode:: JUMP
1408+
.. opcode:: JUMP_NO_INTERRUPT
1409+
.. opcode:: POP_JUMP_IF_FALSE
1410+
.. opcode:: POP_JUMP_IF_TRUE
1411+
.. opcode:: POP_JUMP_IF_NONE
1412+
.. opcode:: POP_JUMP_IF_NOT_NONE
1413+
1414+
Undirected relative jump instructions which are replaced by their
1415+
directed (forward/backward) counterparts by the assembler.
1416+
1417+
.. opcode:: LOAD_METHOD
1418+
1419+
Optimized unbound method lookup. Emitted as a ``LOAD_ATTR`` opcode
1420+
with a flag set in the arg.
1421+
13431422

13441423
.. _opcode_collections:
13451424

@@ -1349,6 +1428,10 @@ Opcode collections
13491428
These collections are provided for automatic introspection of bytecode
13501429
instructions:
13511430

1431+
.. versionchanged:: 3.12
1432+
The collections now contain pseudo instructions as well. These are
1433+
opcodes with values ``>= MIN_PSEUDO_OPCODE``.
1434+
13521435
.. data:: opname
13531436

13541437
Sequence of operation names, indexable using the bytecode.
@@ -1364,6 +1447,13 @@ instructions:
13641447
Sequence of all compare operation names.
13651448

13661449

1450+
.. data:: hasarg
1451+
1452+
Sequence of bytecodes that use their argument.
1453+
1454+
.. versionadded:: 3.12
1455+
1456+
13671457
.. data:: hasconst
13681458

13691459
Sequence of bytecodes that access a constant.
@@ -1400,3 +1490,9 @@ instructions:
14001490
.. data:: hascompare
14011491

14021492
Sequence of bytecodes of Boolean operations.
1493+
1494+
.. data:: hasexc
1495+
1496+
Sequence of bytecodes that set an exception handler.
1497+
1498+
.. versionadded:: 3.12

0 commit comments

Comments
 (0)