Clarify which variables appear in function.__closure__
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Python
- Estrellas
- 77.2k
- Forks
- 35.9k
- Métricas de merge de PR
- Métricas de PR pendientes
Descripción
While working with nested functions, I observed that function.__closure__ only
contains cells for variables that are actually referenced inside the inner
function body. Variables defined in the enclosing scope but not used in the
inner function do not appear in co_freevars and therefore do not appear in
function.__closure__.
Example:
def outer():
x = 1
y = 2
z = 3
def inner():
return x
return inner
inner.__closure__ # contains only x
This behavior matches the execution model (“free variables”), but the current
documentation only states that __closure__ contains bindings for names listed
in co_freevars. It does not explicitly state that only referenced names are
included.
This PR proposes adding a brief clarification to make this behavior explicit.
Before continuing with the pull request, I would like confirmation from the
documentation team whether this detail should be included in the data model
section.
Linked PRs
- gh-142086
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza en la documentación del modelo de datos de Python y revisa la descripción existente de function.closure junto con co_freevars. Aclara que solo aparecen los nombres a los que hace referencia la función interna y confirma la redacción con el equipo de documentación antes de continuar; se considera terminado cuando el comportamiento está explícito en la sección pertinente.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- documentation
- Tipo de issue
- Documentación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100