Andrei Kulakov <andrei....@gmail.com> added the comment:

My last comment was wrong, the issue I linked is unrelated.

I think the actual issue here is the code here:
https://github.com/python/cpython/blob/4b97d974ecca9cce532be55410fe851eb9fdcf21/Lib/tempfile.py#L826

If `path` is a file that causes a permission error, `rmtree` is called and 
causes a NotADirectory error.

This can be confusing when debugging and can lead to a bug if user's code tries 
to catch a PermissionError it expects but instead gets NotADirectory error.

A solution is probably to check if path is a file and error is PermissionError 
and if ignore_errors=False, re-raise it instead of calling rmtree(). If 
ignore_errors=True, return instead of calling rmtree().

I don't have windows so can't test the OP code with this approach.

Serhiy: adding you since you wrote `def onerror()` in tempfile module, do you 
think that is the cause of the issue and the right solution for it?

----------
nosy: +kj, serhiy.storchaka

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue43153>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to