def call_signatures(self): """ Return the function object of the call you're currently in. E.g. if the cursor is here:: abs(# <-- cursor is here This would return the ``abs`` function. On the other hand:: abs()# <-- cursor is here This would return ``None``. :rtype: list of :class:`api_classes.CallDef` """ call, index = self._func_call_and_param_index() if call is None: return [] user_stmt = self._user_stmt() with common.scale_speed_settings(settings.scale_call_signatures): _callable = lambda: evaluate.follow_call(call) origins = cache.cache_call_signatures(_callable, user_stmt) debug.speed('func_call followed') return [ api_classes.CallDef(o, index, call) for o in origins if o.isinstance(er.Function, er.Instance, er.Class) ]
def get_in_function_call(self): """ Return the function, that the cursor is in, e.g.: >>> isinstance(| # | <-- cursor is here This would return the `isinstance` function. In contrary: >>> isinstance()| # | <-- cursor is here This would return `None`. """ def check_user_stmt(user_stmt): if user_stmt is None \ or not isinstance(user_stmt, parsing.Statement): return None, 0 ass = helpers.fast_parent_copy(user_stmt.get_assignment_calls()) call, index, stop = helpers.scan_array_for_pos(ass, self.pos) return call, index def check_cache(): """ Do the parsing with a part parser, therefore reduce ressource costs. TODO this is not working with multi-line docstrings, improve. """ if self.source_path is None: return None, 0 try: timestamp, parser = builtin.CachedModule.cache[ self.source_path] except KeyError: return None, 0 part_parser = self.module.get_part_parser() user_stmt = part_parser.user_stmt call, index = check_user_stmt(user_stmt) if call: old_stmt = parser.module.get_statement_for_position(self.pos) if old_stmt is None: return None, 0 old_call, old_index = check_user_stmt(old_stmt) if old_call: # compare repr because that should definitely be the same. # Otherwise the whole thing is out of sync. if repr(old_call) == repr(call): # return the index of the part_parser return old_call, index return None, 0 else: raise NotFoundError() debug.speed('func_call start') try: call, index = check_cache() except NotFoundError: return None debug.speed('func_call parsed') if call is None: # This is a backup, if the above is not successful. user_stmt = self.parser.user_stmt call, index = check_user_stmt(user_stmt) if call is None: return None debug.speed('func_call user_stmt') with helpers.scale_speed_settings(settings.scale_get_in_function_call): origins = evaluate.follow_call(call) debug.speed('func_call followed') if len(origins) == 0: return None # just take entry zero, because we need just one. executable = origins[0] return api_classes.CallDef(executable, index, call)
def get_in_function_call(self): """ Return the function object of the call you're currently in. E.g. if the cursor is here:: >>> abs(# <-- cursor is here This would return the ``abs`` function. On the other hand:: >>> abs()# <-- cursor is here This would return ``None``. :rtype: :class:`api_classes.CallDef` """ def check_user_stmt(user_stmt): if user_stmt is None \ or not isinstance(user_stmt, parsing.Statement): return None, 0 ass = helpers.fast_parent_copy(user_stmt.get_assignment_calls()) call, index, stop = helpers.search_function_call(ass, self.pos) return call, index def check_cache(): """ Do the parsing with a part parser, therefore reduce ressource costs. TODO this is not working with multi-line docstrings, improve. """ if self.source_path is None: return None, 0 try: parser = cache.parser_cache[self.source_path].parser except KeyError: return None, 0 part_parser = self._module.get_part_parser() user_stmt = part_parser.user_stmt call, index = check_user_stmt(user_stmt) if call: old_stmt = parser.module.get_statement_for_position(self.pos) if old_stmt is None: return None, 0 old_call, old_index = check_user_stmt(old_stmt) if old_call: # compare repr because that should definitely be the same. # Otherwise the whole thing is out of sync. if repr(old_call) == repr(call): # return the index of the part_parser return old_call, index return None, 0 else: raise NotFoundError() debug.speed('func_call start') call = None if settings.use_get_in_function_call_cache: try: call, index = check_cache() except NotFoundError: return None user_stmt = self._parser.user_stmt if call is None: # This is a backup, if the above is not successful. call, index = check_user_stmt(user_stmt) if call is None: return None debug.speed('func_call parsed') with common.scale_speed_settings(settings.scale_get_in_function_call): _callable = lambda: evaluate.follow_call(call) origins = cache.cache_get_in_function_call(_callable, user_stmt) debug.speed('func_call followed') if len(origins) == 0: return None # just take entry zero, because we need just one. executable = origins[0] return api_classes.CallDef(executable, index, call)