forked from VimPlug/jedi
ignore decorators if cannot be found (also get rid of DecoratorNotFound exception), fixes #272
This commit is contained in:
@@ -290,10 +290,7 @@ def find_name(scope, name_str, position=None, search_global=False,
|
||||
elif isinstance(r, pr.Function):
|
||||
r = er.Function(r)
|
||||
if r.isinstance(er.Function):
|
||||
try:
|
||||
r = r.get_decorated_func()
|
||||
except er.DecoratorNotFound:
|
||||
continue
|
||||
res_new.append(r)
|
||||
debug.dbg('sfn remove, new: %s, old: %s' % (res_new, result))
|
||||
return res_new
|
||||
|
||||
@@ -28,13 +28,6 @@ import builtin
|
||||
import dynamic
|
||||
|
||||
|
||||
class DecoratorNotFound(LookupError):
|
||||
"""
|
||||
Decorators are sometimes not found, if that happens, that error is raised.
|
||||
"""
|
||||
pass
|
||||
|
||||
|
||||
class Executable(pr.IsScope):
|
||||
"""
|
||||
An instance is also an executable - because __init__ is called
|
||||
@@ -355,10 +348,13 @@ class Function(use_metaclass(cache.CachedMetaClass, pr.IsScope)):
|
||||
|
||||
def get_decorated_func(self, instance=None):
|
||||
decorated_func = self._decorated_func(instance)
|
||||
if decorated_func is None:
|
||||
raise DecoratorNotFound()
|
||||
if decorated_func == self.base_func:
|
||||
return self
|
||||
if decorated_func is None:
|
||||
# If the decorator func is not found, just ignore the decorator
|
||||
# function, because sometimes decorators are just really
|
||||
# complicated.
|
||||
return Function(self.base_func, True)
|
||||
return decorated_func
|
||||
|
||||
def get_magic_method_names(self):
|
||||
|
||||
@@ -115,17 +115,17 @@ MethodDecoratorAsClass().func_with_self(1)
|
||||
|
||||
|
||||
# -----------------
|
||||
# not found decorators
|
||||
# not found decorators (are just ignored)
|
||||
# -----------------
|
||||
@not_found_decorator
|
||||
def just_a_func():
|
||||
return 1
|
||||
|
||||
#? []
|
||||
#? int()
|
||||
just_a_func()
|
||||
|
||||
#? []
|
||||
just_a_func.
|
||||
#? ['__closure__']
|
||||
just_a_func.__closure__
|
||||
|
||||
|
||||
class JustAClass:
|
||||
@@ -133,14 +133,14 @@ class JustAClass:
|
||||
def a(self):
|
||||
return 1
|
||||
|
||||
#? []
|
||||
JustAClass().a.
|
||||
#? []
|
||||
JustAClass().a()
|
||||
#? []
|
||||
JustAClass.a.
|
||||
#? []
|
||||
#? ['__closure__']
|
||||
JustAClass().a.__closure__
|
||||
#? int()
|
||||
JustAClass().a()
|
||||
#? ['__closure__']
|
||||
JustAClass.a.__closure__
|
||||
#? int()
|
||||
JustAClass.a()
|
||||
|
||||
# -----------------
|
||||
# method decorators
|
||||
@@ -192,11 +192,11 @@ class MethodDecoratorDoesntExist(Base):
|
||||
def a(self):
|
||||
#?
|
||||
super().__init__()
|
||||
#?
|
||||
#? str()
|
||||
super().b()
|
||||
#? int()
|
||||
super().c()
|
||||
#?
|
||||
#? float()
|
||||
self.d()
|
||||
|
||||
@doesnt_exist
|
||||
|
||||
Reference in New Issue
Block a user