Skip to content

Commit 999217d

Browse files
Merge branch 'main' into locale-nl_langinfo-alt_digits
2 parents 5640880 + 93b9e6b commit 999217d

File tree

114 files changed

+7376
-4604
lines changed

Some content is hidden

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

114 files changed

+7376
-4604
lines changed

Doc/c-api/code.rst

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,13 @@ bound into a function.
3232
3333
.. c:function:: Py_ssize_t PyCode_GetNumFree(PyCodeObject *co)
3434
35-
Return the number of free variables in a code object.
35+
Return the number of :term:`free (closure) variables <closure variable>`
36+
in a code object.
3637
3738
.. c:function:: int PyUnstable_Code_GetFirstFree(PyCodeObject *co)
3839
39-
Return the position of the first free variable in a code object.
40+
Return the position of the first :term:`free (closure) variable <closure variable>`
41+
in a code object.
4042
4143
.. versionchanged:: 3.13
4244
@@ -144,7 +146,8 @@ bound into a function.
144146
145147
Equivalent to the Python code ``getattr(co, 'co_freevars')``.
146148
Returns a new reference to a :c:type:`PyTupleObject` containing the names of
147-
the free variables. On error, ``NULL`` is returned and an exception is raised.
149+
the :term:`free (closure) variables <closure variable>`. On error, ``NULL`` is returned
150+
and an exception is raised.
148151
149152
.. versionadded:: 3.11
150153

Doc/c-api/tuple.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,8 @@ type.
167167
168168
.. c:member:: const char *name
169169
170-
Name of the struct sequence type.
170+
Fully qualified name of the type; null-terminated UTF-8 encoded.
171+
The name must contain the module name.
171172
172173
.. c:member:: const char *doc
173174

Doc/c-api/unicode.rst

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1438,6 +1438,31 @@ They all return ``NULL`` or ``-1`` if an exception occurs.
14381438
This function returns ``-1`` upon failure, so one should call
14391439
:c:func:`PyErr_Occurred` to check for errors.
14401440
1441+
.. seealso::
1442+
1443+
The :c:func:`PyUnicode_Equal` function.
1444+
1445+
1446+
.. c:function:: int PyUnicode_Equal(PyObject *a, PyObject *b)
1447+
1448+
Test if two strings are equal:
1449+
1450+
* Return ``1`` if *a* is equal to *b*.
1451+
* Return ``0`` if *a* is not equal to *b*.
1452+
* Set a :exc:`TypeError` exception and return ``-1`` if *a* or *b* is not a
1453+
:class:`str` object.
1454+
1455+
The function always succeeds if *a* and *b* are :class:`str` objects.
1456+
1457+
The function works for :class:`str` subclasses, but does not honor custom
1458+
``__eq__()`` method.
1459+
1460+
.. seealso::
1461+
1462+
The :c:func:`PyUnicode_Compare` function.
1463+
1464+
.. versionadded:: 3.14
1465+
14411466
14421467
.. c:function:: int PyUnicode_EqualToUTF8AndSize(PyObject *unicode, const char *string, Py_ssize_t size)
14431468

Doc/data/stable_abi.dat

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Doc/glossary.rst

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,28 @@ Glossary
231231
A variable defined in a class and intended to be modified only at
232232
class level (i.e., not in an instance of the class).
233233

234+
closure variable
235+
A :term:`free variable` referenced from a :term:`nested scope` that is defined in an outer
236+
scope rather than being resolved at runtime from the globals or builtin namespaces.
237+
May be explicitly defined with the :keyword:`nonlocal` keyword to allow write access,
238+
or implicitly defined if the variable is only being read.
239+
240+
For example, in the ``inner`` function in the following code, both ``x`` and ``print`` are
241+
:term:`free variables <free variable>`, but only ``x`` is a *closure variable*::
242+
243+
def outer():
244+
x = 0
245+
def inner():
246+
nonlocal x
247+
x += 1
248+
print(x)
249+
return inner
250+
251+
Due to the :attr:`codeobject.co_freevars` attribute (which, despite its name, only
252+
includes the names of closure variables rather than listing all referenced free
253+
variables), the more general :term:`free variable` term is sometimes used even
254+
when the intended meaning is to refer specifically to closure variables.
255+
234256
complex number
235257
An extension of the familiar real number system in which all numbers are
236258
expressed as a sum of a real part and an imaginary part. Imaginary
@@ -454,6 +476,13 @@ Glossary
454476
the :term:`global interpreter lock` which allows only one thread to
455477
execute Python bytecode at a time. See :pep:`703`.
456478

479+
free variable
480+
Formally, as defined in the :ref:`language execution model <bind_names>`, a free
481+
variable is any variable used in a namespace which is not a local variable in that
482+
namespace. See :term:`closure variable` for an example.
483+
Pragmatically, due to the name of the :attr:`codeobject.co_freevars` attribute,
484+
the term is also sometimes used as a synonym for :term:`closure variable`.
485+
457486
function
458487
A series of statements which returns some value to a caller. It can also
459488
be passed zero or more :term:`arguments <argument>` which may be used in
@@ -1160,16 +1189,12 @@ Glossary
11601189
(subscript) notation uses :class:`slice` objects internally.
11611190

11621191
soft deprecated
1163-
A soft deprecation can be used when using an API which should no longer
1164-
be used to write new code, but it remains safe to continue using it in
1165-
existing code. The API remains documented and tested, but will not be
1166-
developed further (no enhancement).
1167-
1168-
The main difference between a "soft" and a (regular) "hard" deprecation
1169-
is that the soft deprecation does not imply scheduling the removal of the
1170-
deprecated API.
1192+
A soft deprecated API should not be used in new code,
1193+
but it is safe for already existing code to use it.
1194+
The API remains documented and tested, but will not be enhanced further.
11711195

1172-
Another difference is that a soft deprecation does not issue a warning.
1196+
Soft deprecation, unlike normal deprecation, does not plan on removing the API
1197+
and will not emit warnings.
11731198

11741199
See `PEP 387: Soft Deprecation
11751200
<https://peps.python.org/pep-0387/#soft-deprecation>`_.

Doc/library/_thread.rst

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -213,9 +213,8 @@ In addition to these methods, lock objects can also be used via the
213213

214214
.. index:: pair: module; signal
215215

216-
* Threads interact strangely with interrupts: the :exc:`KeyboardInterrupt`
217-
exception will be received by an arbitrary thread. (When the :mod:`signal`
218-
module is available, interrupts always go to the main thread.)
216+
* Interrupts always go to the main thread (the :exc:`KeyboardInterrupt`
217+
exception will be received by that thread.)
219218

220219
* Calling :func:`sys.exit` or raising the :exc:`SystemExit` exception is
221220
equivalent to calling :func:`_thread.exit`.
@@ -229,7 +228,3 @@ In addition to these methods, lock objects can also be used via the
229228
:keyword:`try` ... :keyword:`finally` clauses or executing object
230229
destructors.
231230

232-
* When the main thread exits, it does not do any of its usual cleanup (except
233-
that :keyword:`try` ... :keyword:`finally` clauses are honored), and the
234-
standard I/O files are not flushed.
235-

Doc/library/dis.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,7 @@ iterations of the loop.
14341434
slot ``i`` of the "fast locals" storage in this mapping.
14351435
If the name is not found there, loads it from the cell contained in
14361436
slot ``i``, similar to :opcode:`LOAD_DEREF`. This is used for loading
1437-
free variables in class bodies (which previously used
1437+
:term:`closure variables <closure variable>` in class bodies (which previously used
14381438
:opcode:`!LOAD_CLASSDEREF`) and in
14391439
:ref:`annotation scopes <annotation-scopes>` within class bodies.
14401440

@@ -1463,8 +1463,8 @@ iterations of the loop.
14631463

14641464
.. opcode:: COPY_FREE_VARS (n)
14651465

1466-
Copies the ``n`` free variables from the closure into the frame.
1467-
Removes the need for special code on the caller's side when calling
1466+
Copies the ``n`` :term:`free (closure) variables <closure variable>` from the closure
1467+
into the frame. Removes the need for special code on the caller's side when calling
14681468
closures.
14691469

14701470
.. versionadded:: 3.11
@@ -1937,10 +1937,10 @@ instructions:
19371937

19381938
.. data:: hasfree
19391939

1940-
Sequence of bytecodes that access a free variable. 'free' in this
1941-
context refers to names in the current scope that are referenced by inner
1942-
scopes or names in outer scopes that are referenced from this scope. It does
1943-
*not* include references to global or builtin scopes.
1940+
Sequence of bytecodes that access a :term:`free (closure) variable <closure variable>`.
1941+
'free' in this context refers to names in the current scope that are
1942+
referenced by inner scopes or names in outer scopes that are referenced
1943+
from this scope. It does *not* include references to global or builtin scopes.
19441944

19451945

19461946
.. data:: hasname

Doc/library/functions.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -684,9 +684,10 @@ are always available. They are listed here in alphabetical order.
684684
``__builtins__`` dictionary into *globals* before passing it to :func:`exec`.
685685

686686
The *closure* argument specifies a closure--a tuple of cellvars.
687-
It's only valid when the *object* is a code object containing free variables.
688-
The length of the tuple must exactly match the number of free variables
689-
referenced by the code object.
687+
It's only valid when the *object* is a code object containing
688+
:term:`free (closure) variables <closure variable>`.
689+
The length of the tuple must exactly match the length of the code object'S
690+
:attr:`~codeobject.co_freevars` attribute.
690691

691692
.. audit-event:: exec code_object exec
692693

0 commit comments

Comments
 (0)