MAINT: cleanup use of sys.exc_info#15248
Conversation
This code originates from python 2.6, before there was an `as` clause in `except`. This removes all callers of `numpy.distutils.compat.get_exception`.
| except (DistutilsExecError, CompileError): | ||
| str(get_exception()) | ||
| except (DistutilsExecError, CompileError) as e: | ||
| str(e) |
There was a problem hiding this comment.
Does this actually do anything.
There was a problem hiding this comment.
I mean, in principle it could if someone declares:
class WeirdException(CompileError):
def __str__(self):
print("Yes this does something")
return CompilerError.__str__(self)I was trying to keep the changes in this patch strictly to removing workarounds except E as e:, rather than evaluating whether e was used sensibly in the first place.
There was a problem hiding this comment.
Ha, it was intended to fix an unused variable warning in #12448.
- msg = str(get_exception())
+ str(get_exception())
There was a problem hiding this comment.
My guess is that the fixer thought there might be a side effect in the function call.
There was a problem hiding this comment.
Thanks for the detective work - I think I'd still rather leave that to a follow-up PR - searching for str(e) probably finds a large amount of stuff that can be better written with exception chaining.
There was a problem hiding this comment.
Flake8 doesn't like that file :) But it doesn't complain about unused variables. I think we can improve a lot of messages with f-strings. We could do that now that Python 3.5 has been dropped, but probably better to wait for the next release.
|
Thanks Eric. |
This is similar to #15248, removing the remaining usages of sys.exc_info() that are no longer necessary.
This code originates from python 2.6, before there was an
asclause inexcept.This removes all callers of
numpy.distutils.compat.get_exception.