8000 Merge branch 'main' into pep649-anno · python/cpython@827c53c · GitHub
[go: up one dir, main page]

Skip to content

Commit 827c53c

Browse files
Merge branch 'main' into pep649-anno
2 parents e2e2bde + c4722cd commit 827c53c

Some content is hidden

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

57 files changed

+1292
-226
lines changed

.github/workflows/jit.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,3 +150,21 @@ jobs:
150150
./configure --enable-experimental-jit ${{ matrix.debug && '--with-pydebug' || '--enable-optimizations ' }} --build=x86_64-linux-gnu --host="$HOST" --with-build-python=../build/bin/python3 --with-pkg-config=no ac_cv_buggy_getaddrinfo=no ac_cv_file__dev_ptc=no ac_cv_file__dev_ptmx=yes
151151
make all --jobs 4
152152
./python -m test --ignorefile=Tools/jit/ignore-tests-emulated-linux.txt --multiprocess 0 --timeout 4500 --verbose2 --verbose3
153+
154+
jit-with-disabled-gil:
155+
name: Free-Threaded (Debug)
156+
runs-on: ubuntu-latest
157+
steps:
158+
- uses: actions/checkout@v4
159+
- uses: actions/setup-python@v5
160+
with:
161+
python-version: '3.11'
162+
- name: Build with JIT enabled and GIL disabled
163+
run: |
164+
sudo bash -c "$(wget -O - https://apt.llvm.org/llvm.sh)" ./llvm.sh 18
165+
export PATH="$(llvm-config-18 --bindir):$PATH"
166+
./configure --enable-experimental-jit --with-pydebug --disable-gil
167+
make all --jobs 4
168+ - name: Run tests
169+
run: |
170+
./python -m test --multiprocess 0 --timeout 4500 --verbose2 --verbose3

.github/workflows/mypy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ concurrency:
3434
jobs:
3535
mypy:
3636
strategy:
37+
fail-fast: false
3738
matrix:
3839
target: [
3940
"Lib/_pyrepl",

.github/workflows/reusable-docs.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ jobs:
6262
python Doc/tools/check-warnings.py \
6363
--annotate-diff '${{ env.branch_base }}' '${{ env.branch_pr }}' \
6464
--fail-if-regression \
65-
--fail-if-improved
65+
--fail-if-improved \
66+
--fail-if-new-news-nit
6667
6768
# This build doesn't use problem matchers or check annotations
6869
build_doc_oldest_supported_sphinx:

Doc/c-api/frame.rst

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,17 +121,18 @@ See also :ref:`Reflection <reflection>`.
121121
.. c:function:: PyObject* PyFrame_GetLocals(PyFrameObject *frame)
122122
123123
Get the *frame*'s :attr:`~frame.f_locals` attribute.
124-
If the frame refers to a function or comprehension, this returns
125-
a write-through proxy object that allows modifying the locals.
126-
In all other cases (classes, modules) it returns the :class:`dict`
127-
representing the frame locals directly.
124+
If the frame refers to an :term:`optimized scope`, this returns a
125+
write-through proxy object that allows modifying the locals.
126+
In all other cases (classes, modules, :func:`exec`, :func:`eval`) it returns
127+
the mapping representing the frame locals directly (as described for
128+
:func:`locals`).
128129
129130
Return a :term:`strong reference`.
130131
131132
.. versionadded:: 3.11
132133
133134
.. versionchanged:: 3.13
134-
Return a proxy object for functions and comprehensions.
135+
As part of :pep:`667`, return a proxy object for optimized scopes.
135136
136137
137138
.. c:function:: int PyFrame_GetLineNumber(PyFrameObject *frame)

Doc/glossary.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -889,6 +889,15 @@ Glossary
889889
(methods). Also the ultimate base class of any :term:`new-style
890890
class`.
891891

892+
optimized scope
893+
A scope where target local variable names are reliably known to the
894+
compiler when the code is compiled, allowing optimization of read and
895+
write access to these names. The local namespaces for functions,
896+
generators, coroutines, comprehensions, and generator expressions are
897+
optimized in this fashion. Note: most interpreter optimizations are
898+
applied to all scopes, only those relying on a known set of local
899+
and nonlocal variable names are restricted to optimized scopes.
900+
892901
package
893902
A Python :term:`module` which can contain submodules or recursively,
894903
subpackages. Technically, a package is a Python module with a

Doc/library/code.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ build applications which provide an interactive interpreter prompt.
1818
This class deals with parsing and interpreter state (the user's namespace); it
1919
does not deal with input buffering or prompting or input file naming (the
2020
filename is always passed in explicitly). The optional *locals* argument
21-
specifies the dictionary in which code will be executed; it defaults to a newly
22-
created dictionary with key ``'__name__'`` set to ``'__console__'`` and key
23-
``'__doc__'`` set to ``None``.
21+
specifies a mapping to use as the namespace in which code will be executed;
22+
it defaults to a newly created dictionary with key ``'__name__'`` set to
23+
``'__console__'`` and key ``'__doc__'`` set to ``None``.
2424

2525

2626
.. class:: InteractiveConsole(locals=None, filename="<console>", local_exit=False)

Doc/library/dataclasses.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,8 @@ methods will raise a :exc:`FrozenInstanceError` when invoked.
616616
There is a tiny performance penalty when using ``frozen=True``:
617617
:meth:`~object.__init__` cannot use simple assignment to initialize fields, and
618618
must use :meth:`!object.__setattr__`.
619-
.. Make sure to not remove "object" from "object.__setattr__" in the above markup
619+
620+
.. Make sure to not remove "object" from "object.__setattr__" in the above markup!
620621
621622
.. _dataclasses-inheritance:
622623

Doc/library/functions.rst

Lines changed: 72 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -543,18 +543,19 @@ are always available. They are listed here in alphabetical order.
543543

544544
The *expression* argument is parsed and evaluated as a Python expression
545545
(technically speaking, a condition list) using the *globals* and *locals*
546-
dictionaries as global and local namespace. If the *globals* dictionary is
546+
mappings as global and local namespace. If the *globals* dictionary is
547547
present and does not contain a value for the key ``__builtins__``, a
548548
reference to the dictionary of the built-in module :mod:`builtins` is
549549
inserted under that key before *expression* is parsed. That way you can
550550
control what builtins are available to the executed code by inserting your
551551
own ``__builtins__`` dictionary into *globals* before passing it to
552-
:func:`eval`. If the *locals* dictionary is omitted it defaults to the
553-
*globals* dictionary. If both dictionaries are omitted, the expression is
552+
:func:`eval`. If the *locals* mapping is omitted it defaults to the
553+
*globals* dictionary. If both mappings are omitted, the expression is
554554
executed with the *globals* and *locals* in the environment where
555-
:func:`eval` is called. Note, *eval()* does not have access to the
555+
:func:`eval` is called. Note, *eval()* will only have access to the
556556
:term:`nested scopes <nested scope>` (non-locals) in the enclosing
557-
environment.
557+
environment if they are already referenced in the scope that is calling
558+
:func:`eval` (e.g. via a :keyword:`nonlocal` statement).
558559

559560
Example:
560561

@@ -587,6 +588,11 @@ are always available. They are listed here in alphabetical order.
587588

588589
The *globals* and *locals* arguments can now be passed as keywords.
589590

591+
.. versionchanged:: 3.13
592+
593+
The semantics of the default *locals* namespace have been adjusted as
594+
described for the :func:`locals` builtin.
595+
590596
.. index:: pair: built-in function; exec
591597

592598
.. function:: exec(source, /, globals=None, locals=None, *, closure=None)
@@ -608,9 +614,19 @@ are always available. They are listed here in alphabetical order.
608614
will be used for both the global and the local variables. If *globals* and
609615
*locals* are given, they are used for the global and local variables,
610616
respectively. If provided, *locals* can be any mapping object. Remember
611-
that at the module level, globals and locals are the same dictionary. If exec
612-
gets two separate objects as *globals* and *locals*, the code will be
613-
executed as if it were embedded in a class definition.
617+
that at the module level, globals and locals are the same dictionary.
618+
619+
.. note::
620+
621+
When ``exec`` gets two separate objects as *globals* and *locals*, the
622+
code will be executed as if it were embedded in a class definition. This
623+
means functions and classes defined in the executed code will not be able
624+
to access variables assigned at the top level (as the "top level"
625+
variables are treated as class variables in a class definition).
626+
Passing a :class:`collections.ChainMap` instance as *globals* allows name
627+
lookups to be chained across multiple mappings without triggering this
628+
behaviour. Values assigned to top level names in the executed code can be
629+
retrieved by passing an empty dictionary as the first entry in the chain.
614630

615631
If the *globals* dictionary does not contain a value for the key
616632
``__builtins__``, a reference to the dictionary of the built-in module
@@ -631,7 +647,7 @@ are always available. They are listed here in alphabetical order.
631647
.. note::
632648

633649
The built-in functions :func:`globals` and :func:`locals` return the current
634-
global and local dictionary, respectively, which may be useful to pass around
650+
global and local namespace, respectively, which may be useful to pass around
635651
for use as the second and third argument to :func:`exec`.
636652

637653
.. note::
@@ -647,6 +663,11 @@ are always available. They are listed here in alphabetical order.
647663

648664
The *globals* and *locals* arguments can now be passed as keywords.
649665

666+
.. versionchanged:: 3.13
667+
668+
The semantics of the default *locals* namespace have been adjusted as
669+
described for the :func:`locals` builtin.
670+
650671

651672
.. function:: filter(function, iterable)
652673

@@ -1052,39 +1073,51 @@ are always available. They are listed here in alphabetical order.
10521073
variable names as the keys, and their currently bound references as the
10531074
values.
10541075

1055-
At module scope, as well as when using ``exec()`` or ``eval()`` with a
1056-
single namespace, this function returns the same namespace as ``globals()``.
1076+
At module scope, as well as when using :func:`exec` or :func:`eval` with
1077+
a single namespace, this function returns the same namespace as
1078+
:func:`globals`.
10571079

10581080
At class scope, it returns the namespace that will be passed to the
10591081
metaclass constructor.
10601082

10611083
When using ``exec()`` or ``eval()`` with separate local and global
1062-
namespaces, it returns the local namespace passed in to the function call.
1084+
arguments, it returns the local namespace passed in to the function call.
10631085

10641086
In all of the above cases, each call to ``locals()`` in a given frame of
10651087
execution will return the *same* mapping object. Changes made through
1066-
the mapping object returned from ``locals()`` will be visible as bound,
1067-
rebound, or deleted local variables, and binding, rebinding, or deleting
1068-
local variables will immediately affect the contents of the returned mapping
1069-
object.
1070-
1071-
At function scope (including for generators and coroutines), each call to
1072-
``locals()`` instead returns a fresh dictionary containing the current
1073-
bindings of the function's local variables and any nonlocal cell references.
1074-
In this case, name binding changes made via the returned dict are *not*
1075-
written back to the corresponding local variables or nonlocal cell
1076-
references, and binding, rebinding, or deleting local variables and nonlocal
1077-
cell references does *not* affect the contents of previously returned
1078-
dictionaries.
1088+
the mapping object returned from ``locals()`` will be visible as assigned,
1089+
reassigned, or deleted local variables, and assigning, reassigning, or
1090+
deleting local variables will immediately affect the contents of the
1091+
returned mapping object.
1092+
1093+
In an :term:`optimized scope` (including functions, generators, and
1094+
coroutines), each call to ``locals()`` instead returns a fresh dictionary
1095+
containing the current bindings of the function's local variables and any
1096+
nonlocal cell references. In this case, name binding changes made via the
1097+
returned dict are *not* written back to the corresponding local variables
1098+
or nonlocal cell references, and assigning, reassigning, or deleting local
1099+
variables and nonlocal cell references does *not* affect the contents
1100+
of previously returned dictionaries.
1101+
1102+
Calling ``locals()`` as part of a comprehension in a function, generator, or
1103+
coroutine is equivalent to calling it in the containing scope, except that
1104+
the comprehension's initialised iteration variables will be included. In
1105+
other scopes, it behaves as if the comprehension were running as a nested
1106+
function.
1107+
1108+
Calling ``locals()`` as part of a generator expression is equivalent to
1109+
calling it in a nested generator function.
1110+
1111+
.. versionchanged:: 3.12
1112+
The behaviour of ``locals()`` in a comprehension has been updated as
1113+
described in :pep:`709`.
10791114

10801115
.. versionchanged:: 3.13
1081-
In previous versions, the semantics of mutating the mapping object
1082-
returned from this function were formally undefined. In CPython
1083-
specifically, the mapping returned at function scope could be
1084-
implicitly refreshed by other operations, such as calling ``locals()``
1085-
again. Obtaining the legacy CPython behaviour now requires explicit
1086-
calls to update the initially returned dictionary with the results
1087-
of subsequent calls to ``locals()``.
1116+
As part of :pep:`667`, the semantics of mutating the mapping objects
1117+
returned from this function are now defined. The behavior in
1118+
:term:`optimized scopes <optimized scope>` is now as described above.
1119+
Aside from being defined, the behaviour in other scopes remains
1120+
unchanged from previous versions.
10881121

10891122

10901123
.. function:: map(function, iterable, *iterables)
@@ -1971,14 +2004,18 @@ are always available. They are listed here in alphabetical order.
19712004
:attr:`~object.__dict__` attributes (for example, classes use a
19722005
:class:`types.MappingProxyType` to prevent direct dictionary updates).
19732006

1974-
Without an argument, :func:`vars` acts like :func:`locals`. Note, the
1975-
locals dictionary is only useful for reads since updates to the locals
1976-
dictionary are ignored.
2007+
Without an argument, :func:`vars` acts like :func:`locals`.
19772008

19782009
A :exc:`TypeError` exception is raised if an object is specified but
19792010
it doesn't have a :attr:`~object.__dict__` attribute (for example, if
19802011
its class defines the :attr:`~object.__slots__` attribute).
19812012

2013+
.. versionchanged:: 3.13
2014+
2015+
The result of calling this function without an argument has been
2016+
updated as described for the :func:`locals` builtin.
2017+
2018+
19822019
.. function:: zip(*iterables, strict=False)
19832020

19842021
Iterate over several iterables in parallel, producing tuples with an item

Doc/library/pdb.rst

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,11 @@ The typical usage to inspect a crashed program is::
123123
0
124124
(Pdb)
125125

126+
.. versionchanged:: 3.13
127+
The implementation of :pep:`667` means that name assignments made via ``pdb``
128+
will immediately affect the active scope, even when running inside an
129+
:term:`optimized scope`.
130+
126131

127132
The module defines the following functions; each enters the debugger in a
128133
slightly different way:
@@ -579,18 +584,17 @@ can be overridden by the local file.
579584

580585
.. pdbcommand:: interact
581586

582-
Start an interactive interpreter (using the :mod:`code` module) whose global
583-
namespace contains all the (global and local) names found in the current
584-
scope. Use ``exit()`` or ``quit()`` to exit the interpreter and return to
585-
the debugger.
587+
Start an interactive interpreter (using the :mod:`code` module) in a new
588+
global namespace initialised from the local and global namespaces for the
589+
current scope. Use ``exit()`` or ``quit()`` to exit the interpreter and
590+
return to the debugger.
586591

587592
.. note::
588593

589-
Because interact creates a new global namespace with the current global
590-
and local namespace for execution, assignment to variables will not
591-
affect the original namespaces.
592-
However, modification to the mutable objects will be reflected in the
593-
original namespaces.
594+
As ``interact`` creates a new dedicated namespace for code execution,
595+
assignments to variables will not affect the original namespaces.
596+
However, modifications to any referenced mutable objects will be reflected
597+
in the original namespaces as usual.
594598

595599
.. versionadded:: 3.2
596600

Doc/library/profile.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ functions:
234234
.. function:: runctx(command, globals, locals, filename=None, sort=-1)
235235

236236
This function is similar to :func:`run`, with added arguments to supply the
237-
globals and locals dictionaries for the *command* string. This routine
237+
globals and locals mappings for the *command* string. This routine
238238
executes::
239239

240240
exec(command, globals, locals)

Doc/library/traceback.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ in a :ref:`traceback <traceback-objects>`.
473473
attribute accessed (which also happens when casting it to a :class:`tuple`).
474474
:attr:`~FrameSummary.line` may be directly provided, and will prevent line
475475
lookups happening at all. *locals* is an optional local variable
476-
dictionary, and if supplied the variable representations are stored in the
476+
mapping, and if supplied the variable representations are stored in the
477477
summary for later display.
478478

479479
:class:`!FrameSummary` instances have the following attributes:

Doc/library/typing.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1780,7 +1780,7 @@ without the dedicated syntax, as documented below.
17801780

17811781
.. _typevartuple:
17821782

1783-
.. class:: TypeVarTuple(name, default=typing.NoDefault)
1783+
.. class:: TypeVarTuple(name, *, default=typing.NoDefault)
17841784

17851785
Type variable tuple. A specialized form of :ref:`type variable <typevar>`
17861786
that enables *variadic* generics.
@@ -2546,7 +2546,7 @@ types.
25462546
``__required_keys__`` and ``__optional_keys__`` rely on may not work
25472547
properly, and the values of the attributes may be incorrect.
25482548

2549-
Support for :data:`ReadOnly` is reflected in the following attributes::
2549+
Support for :data:`ReadOnly` is reflected in the following attributes:
25502550

25512551
.. attribute:: __readonly_keys__
25522552

0 commit comments

Comments
 (0)
0