From 7d10d7fffedf58dcd62a597203b1079013009cd6 Mon Sep 17 00:00:00 2001 From: Rajesh Vemulakonda Date: Sat, 29 Nov 2025 19:39:32 +0530 Subject: [PATCH 1/2] doc: clarify which variables appear in function.__closure__ --- Doc/reference/datamodel.rst | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index ebadbc215a0eed..cb622974ae010e 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -569,6 +569,13 @@ Special read-only attributes A cell object has the attribute ``cell_contents``. This can be used to get the value of the cell, as well as set the value. + Only names that are actually referenced in the function body are + listed in :attr:`~codeobject.co_freevars` and therefore produce + entries in ``function.__closure__``. Variables defined in an + enclosing scope but never referenced inside the function do not + appear in the closure. + + Special writable attributes ~~~~~~~~~~~~~~~~~~~~~~~~~~~ From a97014da1bf2ab13ffb517dd19ad9cffa8ec5193 Mon Sep 17 00:00:00 2001 From: Vemulakonda <42494818+Vemulakonda559@users.noreply.github.com> Date: Sat, 29 Nov 2025 19:43:37 +0530 Subject: [PATCH 2/2] doc: adjust wording in function.__closure__ clarification --- Doc/reference/datamodel.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index cb622974ae010e..3c63d0cb87a657 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -570,7 +570,7 @@ Special read-only attributes This can be used to get the value of the cell, as well as set the value. Only names that are actually referenced in the function body are - listed in :attr:`~codeobject.co_freevars` and therefore produce + listed in :attr:`~codeobject.co_freevars` and therefore have entries in ``function.__closure__``. Variables defined in an enclosing scope but never referenced inside the function do not appear in the closure.