forked from VimPlug/jedi
Use raise from instead of weird magic
This commit is contained in:
@@ -1,6 +1,4 @@
|
|||||||
""" A universal module with functions / classes without dependencies. """
|
""" A universal module with functions / classes without dependencies. """
|
||||||
import sys
|
|
||||||
import contextlib
|
|
||||||
import functools
|
import functools
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
@@ -34,7 +32,6 @@ class UncaughtAttributeError(Exception):
|
|||||||
"""
|
"""
|
||||||
Important, because `__getattr__` and `hasattr` catch AttributeErrors
|
Important, because `__getattr__` and `hasattr` catch AttributeErrors
|
||||||
implicitly. This is really evil (mainly because of `__getattr__`).
|
implicitly. This is really evil (mainly because of `__getattr__`).
|
||||||
`hasattr` in Python 2 is even more evil, because it catches ALL exceptions.
|
|
||||||
Therefore this class originally had to be derived from `BaseException`
|
Therefore this class originally had to be derived from `BaseException`
|
||||||
instead of `Exception`. But because I removed relevant `hasattr` from
|
instead of `Exception`. But because I removed relevant `hasattr` from
|
||||||
the code base, we can now switch back to `Exception`.
|
the code base, we can now switch back to `Exception`.
|
||||||
@@ -63,17 +60,13 @@ def reraise_uncaught(func):
|
|||||||
difficult. This decorator is to help us getting there by changing
|
difficult. This decorator is to help us getting there by changing
|
||||||
`AttributeError` to `UncaughtAttributeError` to avoid unexpected catch.
|
`AttributeError` to `UncaughtAttributeError` to avoid unexpected catch.
|
||||||
This helps us noticing bugs earlier and facilitates debugging.
|
This helps us noticing bugs earlier and facilitates debugging.
|
||||||
|
|
||||||
.. note:: Treating StopIteration here is easy.
|
|
||||||
Add that feature when needed.
|
|
||||||
"""
|
"""
|
||||||
@functools.wraps(func)
|
@functools.wraps(func)
|
||||||
def wrapper(*args, **kwds):
|
def wrapper(*args, **kwds):
|
||||||
try:
|
try:
|
||||||
return func(*args, **kwds)
|
return func(*args, **kwds)
|
||||||
except AttributeError:
|
except AttributeError as e:
|
||||||
exc_info = sys.exc_info()
|
raise UncaughtAttributeError(e) from e
|
||||||
UncaughtAttributeError(exc_info[1]).with_traceback(exc_info[2])
|
|
||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user