decorator's that are not found, are now just being ignored / introduced new testing file

This commit is contained in:
David Halter
2012-06-24 20:00:57 +02:00
parent 3650e0ee64
commit 77698599f4
4 changed files with 74 additions and 3 deletions

View File

@@ -34,7 +34,17 @@ import builtin
memoize_caches = []
class DecoratorNotFound(LookupError):
"""
Decorators are sometimes not found, if that happens, that error is raised.
"""
pass
class MultiLevelStopIteration(Exception):
"""
StopIteration's get catched pretty easy by for loops, let errors propagate.
"""
pass
@@ -56,6 +66,7 @@ class MultiLevelAttributeError(BaseException):
return 'Original:\n\n' + ''.join(tb)
def clear_caches():
for m in memoize_caches:
m.clear()
@@ -339,6 +350,8 @@ class Function(object):
return f
def __getattr__(self, name):
if self.decorated_func == None:
raise DecoratorNotFound()
return getattr(self.decorated_func, name)
def __repr__(self):
@@ -379,7 +392,7 @@ class Execution(Executable):
try:
# if it is an instance, we try to execute the __call__().
call_method = self.base.get_subscope_by_name('__call__')
except (AttributeError, KeyError):
except (AttributeError, KeyError, DecoratorNotFound):
debug.warning("no execution possible", self.base)
else:
debug.dbg('__call__', call_method, self.base)
@@ -886,7 +899,12 @@ def get_scopes_for_name(scope, name_str, position=None, search_global=False):
break_scopes = []
# here is the position stuff happening (sorting of variables)
for name in sorted(name_list, key=comparison_func, reverse=True):
try:
p = name.parent.parent if name.parent else None
except DecoratorNotFound:
debug.warning('catched DecoratorNotFound: %s in %s' \
% (name, scope))
continue
if name_str == name.get_code() and p not in break_scopes:
result += handle_non_arrays(name)
# for comparison we need the raw class

View File

@@ -151,6 +151,31 @@ CallClass()()
# properties
# -----------------
class B():
@property
def r(self):
@@ -172,6 +197,8 @@ B().p
##? []
B().p()
property2 = property
# -----------------
# class decorators
# -----------------

View File

@@ -0,0 +1,27 @@
# -----------------
# not found decorators
# -----------------
@not_found_decorator
def just_a_func():
return 1
#? []
just_a_func()
#? []
just_a_func.
class JustAClass:
@not_found_decorator2
def a(self):
return 1
#? []
JustAClass().a.
#? []
JustAClass().a()
#? []
JustAClass.a.
#? []
JustAClass().a()

View File

@@ -222,7 +222,6 @@ exe = fu(list, set, 3, '', d='')
#? str()
exe[3][0]
# -----------------
# generators
# -----------------