@@ -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> `_.
0 commit comments