Makes _delete attribute from TemporaryDirectory public #128643

Promote _delete member of TemporaryDirectory to delete · Issue #128397 · python/cpython · GitHub As suggested here we should make _delete public so that it can be used like this

with TemporaryDirectory() as temp_dir:
    try:
        thing_that_may_raise()
    except Exception:
        temp_dir.delete = False
        raise

Is there a reason your use wouldn’t be covered by the below?

with TemporaryDirectory(delete=False) as temp_dir:
    thing_that_may_raise()
    # not reached if that raises, can explicitly put it in else of try/except
    temp_dir.cleanup()