Skip to content

Commit 4adfb15

Browse files
committed
Merge branch 'master' into format-twos-compl/74756
2 parents f03f6bb + b3e3cc0 commit 4adfb15

File tree

117 files changed

+4744
-3530
lines changed

Some content is hidden

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

117 files changed

+4744
-3530
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ Python/ast_opt.c @isidentical @eclips4
188188
Parser/asdl.py @isidentical @JelleZijlstra @eclips4
189189
Parser/asdl_c.py @isidentical @JelleZijlstra @eclips4
190190
Lib/ast.py @isidentical @JelleZijlstra @eclips4
191+
Lib/_ast_unparse.py @isidentical @JelleZijlstra @eclips4
191192
Lib/test/test_ast/ @eclips4
192193

193194
# Mock

Doc/c-api/type.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ Type Objects
8282
error (e.g. no more watcher IDs available), return ``-1`` and set an
8383
exception.
8484
85+
In free-threaded builds, :c:func:`PyType_AddWatcher` is not thread-safe,
86+
so it must be called at start up (before spawning the first thread).
87+
8588
.. versionadded:: 3.12
8689
8790

Doc/library/dis.rst

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ the following command can be used to display the disassembly of
7676
2 RESUME 0
7777
<BLANKLINE>
7878
3 LOAD_GLOBAL 1 (len + NULL)
79-
LOAD_FAST 0 (alist)
79+
LOAD_FAST_BORROW 0 (alist)
8080
CALL 1
8181
RETURN_VALUE
8282

@@ -215,7 +215,7 @@ Example:
215215
...
216216
RESUME
217217
LOAD_GLOBAL
218-
LOAD_FAST
218+
LOAD_FAST_BORROW
219219
CALL
220220
RETURN_VALUE
221221

@@ -1402,13 +1402,28 @@ iterations of the loop.
14021402
This opcode is now only used in situations where the local variable is
14031403
guaranteed to be initialized. It cannot raise :exc:`UnboundLocalError`.
14041404

1405+
.. opcode:: LOAD_FAST_BORROW (var_num)
1406+
1407+
Pushes a borrowed reference to the local ``co_varnames[var_num]`` onto the
1408+
stack.
1409+
1410+
.. versionadded:: 3.14
1411+
14051412
.. opcode:: LOAD_FAST_LOAD_FAST (var_nums)
14061413

14071414
Pushes references to ``co_varnames[var_nums >> 4]`` and
14081415
``co_varnames[var_nums & 15]`` onto the stack.
14091416

14101417
.. versionadded:: 3.13
14111418

1419+
1420+
.. opcode:: LOAD_FAST_BORROW_LOAD_FAST_BORROW (var_nums)
1421+
1422+
Pushes borrowed references to ``co_varnames[var_nums >> 4]`` and
1423+
``co_varnames[var_nums & 15]`` onto the stack.
1424+
1425+
.. versionadded:: 3.14
1426+
14121427
.. opcode:: LOAD_FAST_CHECK (var_num)
14131428

14141429
Pushes a reference to the local ``co_varnames[var_num]`` onto the stack,
@@ -2023,4 +2038,3 @@ instructions:
20232038

20242039
.. deprecated:: 3.13
20252040
All jumps are now relative. This list is empty.
2026-

Doc/library/linecache.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ The :mod:`linecache` module defines the following functions:
3030

3131
.. index:: triple: module; search; path
3232

33+
If *filename* indicates a frozen module (starting with ``'<frozen '``), the function
34+
will attepmt to get the real file name from ``module_globals['__file__']`` if
35+
*module_globals* is not ``None``.
36+
3337
If a file named *filename* is not found, the function first checks
3438
for a :pep:`302` ``__loader__`` in *module_globals*.
3539
If there is such a loader and it defines a ``get_source`` method,
@@ -38,6 +42,10 @@ The :mod:`linecache` module defines the following functions:
3842
Finally, if *filename* is a relative filename,
3943
it is looked up relative to the entries in the module search path, ``sys.path``.
4044

45+
.. versionchanged:: 3.14
46+
47+
Support *filename* of frozen modules.
48+
4149

4250
.. function:: clearcache()
4351

Doc/reference/compound_stmts.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,8 @@ Additional information on exceptions can be found in section :ref:`exceptions`,
232232
and information on using the :keyword:`raise` statement to generate exceptions
233233
may be found in section :ref:`raise`.
234234

235+
.. versionchanged:: next
236+
Support for optionally dropping grouping parentheses when using multiple exception types. See :pep:`758`.
235237

236238
.. _except:
237239

@@ -247,7 +249,8 @@ An expression-less :keyword:`!except` clause, if present, must be last;
247249
it matches any exception.
248250

249251
For an :keyword:`!except` clause with an expression, the
250-
expression must evaluate to an exception type or a tuple of exception types.
252+
expression must evaluate to an exception type or a tuple of exception types. Parentheses
253+
can be dropped if multiple exception types are provided and the ``as`` clause is not used.
251254
The raised exception matches an :keyword:`!except` clause whose expression evaluates
252255
to the class or a :term:`non-virtual base class <abstract base class>` of the exception object,
253256
or to a tuple that contains such a class.

Doc/whatsnew/3.14.rst

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,33 @@ If you encounter :exc:`NameError`\s or pickling errors coming out of
9090
New features
9191
============
9292

93+
.. _whatsnew314-pep758:
94+
95+
PEP 758 – Allow except and except* expressions without parentheses
96+
------------------------------------------------------------------
97+
98+
The :keyword:`except` and :keyword:`except* <except_star>` expressions now allow
99+
parentheses to be omitted when there are multiple exception types and the ``as`` clause is not used.
100+
For example the following expressions are now valid:
101+
102+
.. code-block:: python
103+
104+
try:
105+
release_new_sleep_token_album()
106+
except AlbumNotFound, SongsTooGoodToBeReleased:
107+
print("Sorry, no new album this year.")
108+
109+
# The same applies to except* (for exception groups):
110+
try:
111+
release_new_sleep_token_album()
112+
except* AlbumNotFound, SongsTooGoodToBeReleased:
113+
print("Sorry, no new album this year.")
114+
115+
Check :pep:`758` for more details.
116+
117+
(Contributed by Pablo Galindo and Brett Cannon in :gh:`131831`.)
118+
119+
93120
.. _whatsnew314-pep649:
94121

95122
PEP 649: deferred evaluation of annotations
@@ -679,6 +706,13 @@ json
679706
(Contributed by Trey Hunner in :gh:`122873`.)
680707

681708

709+
linecache
710+
---------
711+
712+
* :func:`linecache.getline` can retrieve source code for frozen modules.
713+
(Contributed by Tian Gao in :gh:`131638`.)
714+
715+
682716
mimetypes
683717
---------
684718

Grammar/python.gram

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -435,14 +435,18 @@ try_stmt[stmt_ty]:
435435

436436
except_block[excepthandler_ty]:
437437
| invalid_except_stmt_indent
438-
| 'except' e=expression t=['as' z=NAME { z }] ':' b=block {
439-
_PyAST_ExceptHandler(e, (t) ? ((expr_ty) t)->v.Name.id : NULL, b, EXTRA) }
438+
| 'except' e=expressions ':' b=block {
439+
_PyAST_ExceptHandler(e, NULL, b, EXTRA) }
440+
| 'except' e=expression 'as' t=NAME ':' b=block {
441+
_PyAST_ExceptHandler(e, ((expr_ty) t)->v.Name.id, b, EXTRA) }
440442
| 'except' ':' b=block { _PyAST_ExceptHandler(NULL, NULL, b, EXTRA) }
441443
| invalid_except_stmt
442444
except_star_block[excepthandler_ty]:
443445
| invalid_except_star_stmt_indent
444-
| 'except' '*' e=expression t=['as' z=NAME { z }] ':' b=block {
445-
_PyAST_ExceptHandler(e, (t) ? ((expr_ty) t)->v.Name.id : NULL, b, EXTRA) }
446+
| 'except' '*' e=expressions ':' b=block {
447+
_PyAST_ExceptHandler(e, NULL, b, EXTRA) }
448+
| 'except' '*' e=expression 'as' t=NAME ':' b=block {
449+
_PyAST_ExceptHandler(e, ((expr_ty) t)->v.Name.id, b, EXTRA) }
446450
| invalid_except_star_stmt
447451
finally_block[asdl_stmt_seq*]:
448452
| invalid_finally_stmt
@@ -1356,16 +1360,16 @@ invalid_try_stmt:
13561360
| 'try' ':' block* except_star_block+ a='except' [expression ['as' NAME]] ':' {
13571361
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "cannot have both 'except' and 'except*' on the same 'try'") }
13581362
invalid_except_stmt:
1359-
| 'except' a=expression ',' expressions ['as' NAME ] ':' {
1360-
RAISE_SYNTAX_ERROR_STARTING_FROM(a, "multiple exception types must be parenthesized") }
1363+
| 'except' a=expression ',' expressions 'as' NAME ':' {
1364+
RAISE_SYNTAX_ERROR_STARTING_FROM(a, "multiple exception types must be parenthesized when using 'as'") }
13611365
| a='except' expression ['as' NAME ] NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
13621366
| a='except' NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
13631367
| 'except' expression 'as' a=expression {
13641368
RAISE_SYNTAX_ERROR_KNOWN_LOCATION(
13651369
a, "cannot use except statement with %s", _PyPegen_get_expr_name(a)) }
13661370
invalid_except_star_stmt:
1367-
| 'except' '*' a=expression ',' expressions ['as' NAME ] ':' {
1368-
RAISE_SYNTAX_ERROR_STARTING_FROM(a, "multiple exception types must be parenthesized") }
1371+
| 'except' '*' a=expression ',' expressions 'as' NAME ':' {
1372+
RAISE_SYNTAX_ERROR_STARTING_FROM(a, "multiple exception types must be parenthesized when using 'as'") }
13691373
| a='except' '*' expression ['as' NAME ] NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
13701374
| a='except' '*' (NEWLINE | ':') { RAISE_SYNTAX_ERROR("expected one or more exception types") }
13711375
| 'except' '*' expression 'as' a=expression {

Include/internal/pycore_frame.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,12 @@ struct _frame {
2828
PyEval_GetLocals requires a borrowed reference so the actual reference
2929
is stored here */
3030
PyObject *f_locals_cache;
31+
/* A tuple containing strong references to fast locals that were overwritten
32+
* via f_locals. Borrowed references to these locals may exist in frames
33+
* closer to the top of the stack. The references in this tuple act as
34+
* "support" for the borrowed references, ensuring that they remain valid.
35+
*/
36+
PyObject *f_overwritten_fast_locals;
3137
/* The frame data, if this frame object owns the frame */
3238
PyObject *_f_frame_data[1];
3339
};

Include/internal/pycore_magic_number.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,7 @@ Known values:
273273
Python 3.14a6 3618 (Add oparg to END_ASYNC_FOR)
274274
Python 3.14a6 3619 (Renumber RESUME opcode from 149 to 128)
275275
Python 3.14a6 3620 (Optimize bytecode for all/any/tuple called on a genexp)
276+
Python 3.14a7 3621 (Optimize LOAD_FAST opcodes into LOAD_FAST_BORROW)
276277
277278
Python 3.15 will start with 3650
278279
@@ -285,7 +286,7 @@ PC/launcher.c must also be updated.
285286
286287
*/
287288

288-
#define PYC_MAGIC_NUMBER 3620
289+
#define PYC_MAGIC_NUMBER 3621
289290
/* This is equivalent to converting PYC_MAGIC_NUMBER to 2 bytes
290291
(little-endian) and then appending b'\r\n'. */
291292
#define PYC_MAGIC_NUMBER_TOKEN \

0 commit comments

Comments
 (0)