Promote _delete member of TemporaryDirectory to delete
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
Feature or enhancement
Proposal:
TemporaryDirectory.__delete__ gained a delete parameter to support retaining temporary files for diagnostic purposes.
In a running system, you may wish gather diagnostic files on failure, or when a specific signal is received. Supporting this fully requires allowing the decision of whether to delete files to be made after the TemporaryDirectory has been __enter__ed.
Assigning to _delete can achieve this effect, but _delete is not part of the public interface.
Therefore, I propose changing TemporaryDirectory._delete to TemporaryDirectory.delete.
Example use to retain temporary files on error:
with TemporaryDirectory() as temp_dir:
try:
thing_that_may_raise()
except Exception:
temp_dir.delete = False
raise
Alternatives considered:
- Provide a function to control this behaviour
- We can always turn
deleteinto a property if necessary
- We can always turn
- Users can provide subclasses of TemporaryDirectory to achieve this
- Temporary Directory doesn't have enough of a public API for this to be viable. Using the private API would be morally equivalent to modifying
_delete, and modifying_deletewould be easier.
- Temporary Directory doesn't have enough of a public API for this to be viable. Using the private API would be morally equivalent to modifying
- Users can provide a wrapper to prevent
__exit__from being called__del__might be implemented in the future, as it is forTemporaryFile.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
- gh-128643
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 con TemporaryDirectory y su ciclo de vida enter/exit, centrándote en cómo se almacena y utiliza la decisión de eliminación después de entrar en el contexto. Revisa el PR enlazado gh-128643 para consultar el trabajo que ya está en curso; se considera terminado cuando el atributo público delete permite cambiar el comportamiento de limpieza después de enter.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- python
- Área
- operating-systems
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 25/100