1
0
forked from VimPlug/jedi

Add common.rethrow_uncaught

This commit is contained in:
Takafumi Arakaki
2013-03-13 23:21:15 +01:00
parent 74a9501bd7
commit e42ff9e762
2 changed files with 24 additions and 1 deletions

View File

@@ -81,6 +81,16 @@ else:
eval(compile("""def exec_function(source, global_map): eval(compile("""def exec_function(source, global_map):
exec source in global_map """, 'blub', 'exec')) exec source in global_map """, 'blub', 'exec'))
# re-raise function
if is_py3k:
def reraise(exception, traceback):
raise exception.with_traceback(traceback)
else:
eval(compile("""
def reraise(exception, traceback):
raise exception, None, traceback
""", 'blub', 'exec'))
# StringIO (Python 2.5 has no io module), so use io only for py3k # StringIO (Python 2.5 has no io module), so use io only for py3k
try: try:
from StringIO import StringIO from StringIO import StringIO

View File

@@ -1,8 +1,10 @@
""" A universal module with functions / classes without dependencies. """ """ A universal module with functions / classes without dependencies. """
import sys
import contextlib import contextlib
import functools
import tokenize import tokenize
from _compatibility import next from _compatibility import next, reraise
import debug import debug
import settings import settings
@@ -33,6 +35,17 @@ class MultiLevelAttributeError(Exception):
return 'Original:\n\n' + ''.join(tb) return 'Original:\n\n' + ''.join(tb)
def rethrow_uncaught(func):
@functools.wraps(func)
def wrapper(*args, **kwds):
try:
return func(*args, **kwds)
except AttributeError:
exc_info = sys.exc_info()
reraise(MultiLevelAttributeError, exc_info[2])
return wrapper
class PushBackIterator(object): class PushBackIterator(object):
def __init__(self, iterator): def __init__(self, iterator):
self.pushes = [] self.pushes = []