This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: onerror in tempfile has an invalid raise expression
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.10
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: erlendaasland, eryksun, max-sixty, serhiy.storchaka
Priority: normal Keywords:

Created on 2021-04-02 17:57 by max-sixty, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (4)
msg390084 - (view) Author: Maximilian Roos (max-sixty) Date: 2021-04-02 17:57
The raise expression [here](https://github.com/python/cpython/blob/ad442a674ca443feec43a88a2d3671784712e550/Lib/tempfile.py#L826) isn't valid, since it isn't in an except block.

It'll still raise, given it's invalid, though not with the exception it should be raising with...

I think this diff will fix it, I can put this in as a PR if that's reasonable. Though I'm not sure how to test it — we need to generate an error that's not covered by the existing cases. 

```diff

diff --git a/Lib/tempfile.py b/Lib/tempfile.py
index efcf7a7fb3..227e25d0fc 100644
--- a/Lib/tempfile.py
+++ b/Lib/tempfile.py
@@ -823,7 +823,7 @@ def resetperms(path):
                 pass
             else:
                 if not ignore_errors:
-                    raise
+                    raise exc_info[1]
 
         _shutil.rmtree(name, onerror=onerror)

```
msg390090 - (view) Author: Erlend E. Aasland (erlendaasland) * (Python triager) Date: 2021-04-02 19:12
Adding Serhiy, who added the code in question in commit e9b51c0ad81da1da11ae65840ac8b50a8521373c (GH-10320, bpo-26660, bpo-35144).
msg390091 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2021-04-02 19:17
> It'll still raise, given it's invalid, though not with the 
> exception it should be raising with...

onerror() is always called to handle an exception, and `raise` will re-raise that exception. Is there a specific case where this isn't working as expected for you?
msg390096 - (view) Author: Maximilian Roos (max-sixty) Date: 2021-04-02 20:24
I see @eryksun — by convention `onerror` is always called in an except block, and so having a bare `raise` outside of an explicit except block is OK.

Thanks for clarifying. I'll close this.
History
Date User Action Args
2022-04-11 14:59:43adminsetgithub: 87873
2021-04-02 20:24:01max-sixtysetstatus: open -> closed
resolution: not a bug
messages: + msg390096

stage: resolved
2021-04-02 19:17:20eryksunsetnosy: + eryksun
messages: + msg390091
2021-04-02 19:12:49erlendaaslandsetnosy: + erlendaasland, serhiy.storchaka
messages: + msg390090
2021-04-02 17:57:47max-sixtycreate