Open graingert opened 2 weeks ago
I think this __del__
needs to issue the resource warning:
I think this del needs to issue the resource warning:
On POSIX, the docs say
Opening the temporary file again by its name while it is still open works as follows: On POSIX the file can always be opened again.
So technically, no warning should be issued since you can leave it opened (I think?).
I don't see how that's related? The resource delete on __del__
is a last resort, and it needs to issue a ResourceWarning so that code that fails to finalise explicitly can be detected
Ah sorry, I misunderstood the "open again" in the sense that you can leave the descriptor hanging. My bad. However, non-named temporary files say:
It will be destroyed as soon as it is closed (including an implicit close when the object is garbage collected).
Should implicit close emit a warning in this case? Actually, why is there a warning on Windows?
Should implicit close emit a warning in this case?
Yes, all implicit closing of resources on GC should issue a ResourceWarning
I suspect the way to go here is to replace _TemporaryFileCloser with a weakref.finalize
I suspect the way to go here is to replace _TemporaryFileCloser with a weakref.finalize
Looks like it, TemporaryDirectory
is doing something similar:
Bug report
Bug description:
when run with
python -Werror demo.py
nothing happensif you open a file normally you get a ResourceWarning:
it appears that you do get a ResourceWarning on windows, but I've only seen it in CI I havn't reproduced locally yet
CPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs