Skip to content

Commit b03a330

Browse files
authored
Merge branch 'python:main' into main
2 parents 4d61963 + 7db1d2e commit b03a330

File tree

104 files changed

+1396
-977
lines changed

Some content is hidden

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

104 files changed

+1396
-977
lines changed

.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: 86 additions & 6 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

@@ -1349,13 +1351,74 @@ iterations of the loop.
13491351
.. opcode:: HAVE_ARGUMENT
13501352

13511353
This is not really an opcode. It identifies the dividing line between
1352-
opcodes which don't use their argument and those that do
1353-
(``< 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.
13541359

13551360
.. versionchanged:: 3.6
13561361
Now every instruction has an argument, but opcodes ``< HAVE_ARGUMENT``
13571362
ignore it. Before, only opcodes ``>= HAVE_ARGUMENT`` had an argument.
13581363

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+
13591422

13601423
.. _opcode_collections:
13611424

@@ -1365,6 +1428,10 @@ Opcode collections
13651428
These collections are provided for automatic introspection of bytecode
13661429
instructions:
13671430

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

13701437
Sequence of operation names, indexable using the bytecode.
@@ -1380,6 +1447,13 @@ instructions:
13801447
Sequence of all compare operation names.
13811448

13821449

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

13851459
Sequence of bytecodes that access a constant.
@@ -1416,3 +1490,9 @@ instructions:
14161490
.. data:: hascompare
14171491

14181492
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

Doc/library/hashlib.rst

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -300,23 +300,17 @@ include a `salt <https://en.wikipedia.org/wiki/Salt_%28cryptography%29>`_.
300300

301301
>>> from hashlib import pbkdf2_hmac
302302
>>> our_app_iters = 500_000 # Application specific, read above.
303-
>>> dk = pbkdf2_hmac('sha256', b'password', b'bad salt'*2, our_app_iters)
303+
>>> dk = pbkdf2_hmac('sha256', b'password', b'bad salt' * 2, our_app_iters)
304304
>>> dk.hex()
305305
'15530bba69924174860db778f2c6f8104d3aaf9d26241840c8c4a641c8d000a9'
306306

307-
.. versionadded:: 3.4
308-
309-
.. note::
307+
Function only available when Python is compiled with OpenSSL.
310308

311-
A fast implementation of *pbkdf2_hmac* is available with OpenSSL. The
312-
Python implementation uses an inline version of :mod:`hmac`. It is about
313-
three times slower and doesn't release the GIL.
314-
315-
.. deprecated:: 3.10
309+
.. versionadded:: 3.4
316310

317-
Slow Python implementation of *pbkdf2_hmac* is deprecated. In the
318-
future the function will only be available when Python is compiled
319-
with OpenSSL.
311+
.. versionchanged:: 3.12
312+
Function now only available when Python is built with OpenSSL. The slow
313+
pure Python implementation has been removed.
320314

321315
.. function:: scrypt(password, *, salt, n, r, p, maxmem=0, dklen=64)
322316

Doc/library/http.server.rst

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ This module defines classes for implementing HTTP servers.
2020
.. warning::
2121

2222
:mod:`http.server` is not recommended for production. It only implements
23-
basic security checks.
23+
:ref:`basic security checks <http.server-security>`.
2424

2525
One class, :class:`HTTPServer`, is a :class:`socketserver.TCPServer` subclass.
2626
It creates and listens at the HTTP socket, dispatching the requests to a
@@ -499,3 +499,14 @@ following command runs an HTTP/1.1 conformant server::
499499
the ``--cgi`` option::
500500

501501
python -m http.server --cgi
502+
503+
.. _http.server-security:
504+
505+
Security Considerations
506+
-----------------------
507+
508+
.. index:: pair: http.server; security
509+
510+
:class:`SimpleHTTPRequestHandler` will follow symbolic links when handling
511+
requests, this makes it possible for files outside of the specified directory
512+
to be served.

0 commit comments

Comments
 (0)