forked from VimPlug/jedi
get rid of the whole is_callable stuff, because now we can just check for hasattr(obj, 'py__call__')
This commit is contained in:
@@ -585,7 +585,7 @@ class Script(object):
|
|||||||
except (IndexError, AttributeError):
|
except (IndexError, AttributeError):
|
||||||
pass
|
pass
|
||||||
return [classes.CallSignature(self._evaluator, o, call, index, key_name)
|
return [classes.CallSignature(self._evaluator, o, call, index, key_name)
|
||||||
for o in origins if o.is_callable()]
|
for o in origins if hasattr(o, 'py__call__')]
|
||||||
|
|
||||||
def _analysis(self):
|
def _analysis(self):
|
||||||
#statements = set(chain(*self._parser.module().used_names.values()))
|
#statements = set(chain(*self._parser.module().used_names.values()))
|
||||||
|
|||||||
@@ -335,7 +335,7 @@ class BaseDefinition(object):
|
|||||||
Otherwise returns a list of `Definition` that represents the params.
|
Otherwise returns a list of `Definition` that represents the params.
|
||||||
"""
|
"""
|
||||||
followed = self._follow_statements_imports()
|
followed = self._follow_statements_imports()
|
||||||
if not followed or not followed[0].is_callable():
|
if not followed or not hasattr(followed[0], 'py__call__'):
|
||||||
raise AttributeError()
|
raise AttributeError()
|
||||||
followed = followed[0] # only check the first one.
|
followed = followed[0] # only check the first one.
|
||||||
|
|
||||||
|
|||||||
@@ -195,10 +195,6 @@ class CompiledObject(Base):
|
|||||||
def get_imports(self):
|
def get_imports(self):
|
||||||
return [] # Builtins don't have imports
|
return [] # Builtins don't have imports
|
||||||
|
|
||||||
def is_callable(self):
|
|
||||||
"""Check if the object has a ``__call__`` method."""
|
|
||||||
return hasattr(self.obj, '__call__')
|
|
||||||
|
|
||||||
|
|
||||||
class CompiledName(FakeName):
|
class CompiledName(FakeName):
|
||||||
def __init__(self, obj, name):
|
def __init__(self, obj, name):
|
||||||
@@ -248,8 +244,7 @@ def dotted_from_fs_path(fs_path, sys_path=None):
|
|||||||
# C:\path\to\Lib
|
# C:\path\to\Lib
|
||||||
path = ''
|
path = ''
|
||||||
for s in sys_path:
|
for s in sys_path:
|
||||||
if (fs_path.startswith(s) and
|
if (fs_path.startswith(s) and len(path) < len(s)):
|
||||||
len(path) < len(s)):
|
|
||||||
path = s
|
path = s
|
||||||
return _path_re.sub('', fs_path[len(path):].lstrip(os.path.sep)).replace(os.path.sep, '.')
|
return _path_re.sub('', fs_path[len(path):].lstrip(os.path.sep)).replace(os.path.sep, '.')
|
||||||
|
|
||||||
|
|||||||
@@ -165,13 +165,6 @@ class Instance(use_metaclass(CachedMetaClass, Executable)):
|
|||||||
names.append(InstanceElement(self._evaluator, self, var, True))
|
names.append(InstanceElement(self._evaluator, self, var, True))
|
||||||
yield self, names
|
yield self, names
|
||||||
|
|
||||||
def is_callable(self):
|
|
||||||
try:
|
|
||||||
self.get_subscope_by_name('__call__')
|
|
||||||
return True
|
|
||||||
except KeyError:
|
|
||||||
return False
|
|
||||||
|
|
||||||
def get_index_types(self, index_array):
|
def get_index_types(self, index_array):
|
||||||
|
|
||||||
indexes = iterable.create_indexes_or_slices(self._evaluator, index_array)
|
indexes = iterable.create_indexes_or_slices(self._evaluator, index_array)
|
||||||
@@ -257,9 +250,6 @@ class InstanceElement(use_metaclass(CachedMetaClass, pr.Base)):
|
|||||||
def isinstance(self, *cls):
|
def isinstance(self, *cls):
|
||||||
return isinstance(self.var, cls)
|
return isinstance(self.var, cls)
|
||||||
|
|
||||||
def is_callable(self):
|
|
||||||
return self.var.is_callable()
|
|
||||||
|
|
||||||
def py__call__(self, evaluator, params, evaluate_generator=False):
|
def py__call__(self, evaluator, params, evaluate_generator=False):
|
||||||
# TODO this should be working nicer.
|
# TODO this should be working nicer.
|
||||||
if isinstance(self.var, (compiled.CompiledObject, Instance)):
|
if isinstance(self.var, (compiled.CompiledObject, Instance)):
|
||||||
@@ -350,9 +340,6 @@ class Class(use_metaclass(CachedMetaClass, pr.IsScope)):
|
|||||||
return sub
|
return sub
|
||||||
raise KeyError("Couldn't find subscope.")
|
raise KeyError("Couldn't find subscope.")
|
||||||
|
|
||||||
def is_callable(self):
|
|
||||||
return True
|
|
||||||
|
|
||||||
@common.safe_property
|
@common.safe_property
|
||||||
def name(self):
|
def name(self):
|
||||||
return self.base.name
|
return self.base.name
|
||||||
@@ -434,9 +421,6 @@ class Function(use_metaclass(CachedMetaClass, pr.IsScope)):
|
|||||||
def get_magic_function_scope(self):
|
def get_magic_function_scope(self):
|
||||||
return compiled.magic_function_class
|
return compiled.magic_function_class
|
||||||
|
|
||||||
def is_callable(self):
|
|
||||||
return True
|
|
||||||
|
|
||||||
def py__call__(self, evaluator, params, evaluate_generator=False):
|
def py__call__(self, evaluator, params, evaluate_generator=False):
|
||||||
stmts = FunctionExecution(evaluator, self, params) \
|
stmts = FunctionExecution(evaluator, self, params) \
|
||||||
.get_return_types(evaluate_generator)
|
.get_return_types(evaluate_generator)
|
||||||
|
|||||||
@@ -139,13 +139,6 @@ class Base(object):
|
|||||||
scope = scope.parent
|
scope = scope.parent
|
||||||
return scope
|
return scope
|
||||||
|
|
||||||
def is_callable(self):
|
|
||||||
"""
|
|
||||||
By default parser objects are not callable, we make them callable by
|
|
||||||
the ``evaluate.representation`` objects.
|
|
||||||
"""
|
|
||||||
return False
|
|
||||||
|
|
||||||
def space(self, from_pos, to_pos):
|
def space(self, from_pos, to_pos):
|
||||||
"""Return the space between two tokens"""
|
"""Return the space between two tokens"""
|
||||||
linecount = to_pos[0] - from_pos[0]
|
linecount = to_pos[0] - from_pos[0]
|
||||||
|
|||||||
Reference in New Issue
Block a user