[New-bugs-announce] [issue43707] onerror in tempfile has an invalid raise expression

Maximilian Roos report at bugs.python.org
Fri Apr 2 13:57:47 EDT 2021


New submission from Maximilian Roos <m at maxroos.com>:

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)

```

----------
components: Library (Lib)
messages: 390084
nosy: max-sixty
priority: normal
severity: normal
status: open
title: onerror in tempfile has an invalid raise expression
type: behavior
versions: Python 3.10

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43707>
_______________________________________


More information about the New-bugs-announce mailing list