mirror of
https://github.com/davidhalter/jedi.git
synced 2026-05-24 17:28:36 +08:00
Simplify decorators, make them easier to read in debugging mode.
This commit is contained in:
@@ -293,6 +293,7 @@ class NameFinder(object):
|
|||||||
|
|
||||||
for name in names:
|
for name in names:
|
||||||
typ = name.get_definition()
|
typ = name.get_definition()
|
||||||
|
print(name, typ)
|
||||||
if typ.isinstance(pr.ForStmt):
|
if typ.isinstance(pr.ForStmt):
|
||||||
for_types = self._evaluator.eval_element(typ.children[-3])
|
for_types = self._evaluator.eval_element(typ.children[-3])
|
||||||
for_types = iterable.get_iterator_types(for_types)
|
for_types = iterable.get_iterator_types(for_types)
|
||||||
|
|||||||
@@ -459,9 +459,9 @@ class Function(use_metaclass(CachedMetaClass, Wrapper)):
|
|||||||
self.decorates = None
|
self.decorates = None
|
||||||
|
|
||||||
@memoize_default()
|
@memoize_default()
|
||||||
def _decorated_func(self):
|
def get_decorated_func(self):
|
||||||
"""
|
"""
|
||||||
Returns the function, that is to be executed in the end.
|
Returns the function, that should to be executed in the end.
|
||||||
This is also the places where the decorators are processed.
|
This is also the places where the decorators are processed.
|
||||||
"""
|
"""
|
||||||
f = self.base_func
|
f = self.base_func
|
||||||
@@ -480,7 +480,7 @@ class Function(use_metaclass(CachedMetaClass, Wrapper)):
|
|||||||
|
|
||||||
if not len(dec_results):
|
if not len(dec_results):
|
||||||
debug.warning('decorator not found: %s on %s', dec, self.base_func)
|
debug.warning('decorator not found: %s on %s', dec, self.base_func)
|
||||||
return None
|
return self
|
||||||
decorator = dec_results.pop()
|
decorator = dec_results.pop()
|
||||||
if dec_results:
|
if dec_results:
|
||||||
debug.warning('multiple decorators found %s %s',
|
debug.warning('multiple decorators found %s %s',
|
||||||
@@ -492,7 +492,7 @@ class Function(use_metaclass(CachedMetaClass, Wrapper)):
|
|||||||
wrappers = self._evaluator.execute(decorator, (old_func,))
|
wrappers = self._evaluator.execute(decorator, (old_func,))
|
||||||
if not len(wrappers):
|
if not len(wrappers):
|
||||||
debug.warning('no wrappers found %s', self.base_func)
|
debug.warning('no wrappers found %s', self.base_func)
|
||||||
return None
|
return self
|
||||||
if len(wrappers) > 1:
|
if len(wrappers) > 1:
|
||||||
# TODO resolve issue with multiple wrappers -> multiple types
|
# TODO resolve issue with multiple wrappers -> multiple types
|
||||||
debug.warning('multiple wrappers found %s %s',
|
debug.warning('multiple wrappers found %s %s',
|
||||||
@@ -507,14 +507,6 @@ class Function(use_metaclass(CachedMetaClass, Wrapper)):
|
|||||||
return self
|
return self
|
||||||
return f
|
return f
|
||||||
|
|
||||||
def get_decorated_func(self):
|
|
||||||
"""
|
|
||||||
This function exists for the sole purpose of returning itself if the
|
|
||||||
decorator doesn't turn out to "work", that means we cannot resolve it.
|
|
||||||
In that case ignore the decorator.
|
|
||||||
"""
|
|
||||||
return self._decorated_func() or self
|
|
||||||
|
|
||||||
def get_magic_function_names(self):
|
def get_magic_function_names(self):
|
||||||
return compiled.magic_function_class.get_defined_names()
|
return compiled.magic_function_class.get_defined_names()
|
||||||
|
|
||||||
@@ -535,10 +527,9 @@ class Function(use_metaclass(CachedMetaClass, Wrapper)):
|
|||||||
return getattr(self.base_func, name)
|
return getattr(self.base_func, name)
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
dec_func = self._decorated_func()
|
|
||||||
dec = ''
|
dec = ''
|
||||||
if not self.is_decorated and self.base_func.get_decorators():
|
if self.decorates is not None:
|
||||||
dec = " is " + repr(dec_func)
|
dec = " decorates " + repr(self.decorates)
|
||||||
return "<e%s of %s%s>" % (type(self).__name__, self.base_func, dec)
|
return "<e%s of %s%s>" % (type(self).__name__, self.base_func, dec)
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user