Skip to content

Commit 7d10d7f

Browse files
doc: clarify which variables appear in function.__closure__
1 parent cfcd524 commit 7d10d7f

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

Doc/reference/datamodel.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,13 @@ Special read-only attributes
569569
A cell object has the attribute ``cell_contents``.
570570
This can be used to get the value of the cell, as well as set the value.
571571

572+
Only names that are actually referenced in the function body are
573+
listed in :attr:`~codeobject.co_freevars` and therefore produce
574+
entries in ``function.__closure__``. Variables defined in an
575+
enclosing scope but never referenced inside the function do not
576+
appear in the closure.
577+
578+
572579
Special writable attributes
573580
~~~~~~~~~~~~~~~~~~~~~~~~~~~
574581

0 commit comments

Comments
 (0)