def get_return_values(self, check_yields=False): funcdef = self.tree_node if funcdef.type == 'lambdef': return self.eval_node(funcdef.children[-1]) if check_yields: context_set = NO_CONTEXTS returns = get_yield_exprs(self.evaluator, funcdef) else: returns = funcdef.iter_return_stmts() context_set = docstrings.infer_return_types(self.function_context) context_set |= pep0484.infer_return_types(self.function_context) for r in returns: check = flow_analysis.reachability_check(self, funcdef, r) if check is flow_analysis.UNREACHABLE: debug.dbg('Return unreachable: %s', r) else: if check_yields: context_set |= ContextSet.from_sets( lazy_context.infer() for lazy_context in self._get_yield_lazy_context(r) ) else: try: children = r.children except AttributeError: ctx = compiled.builtin_from_name(self.evaluator, u'None') context_set |= ContextSet(ctx) else: context_set |= self.eval_node(children[1]) if check is flow_analysis.REACHABLE: debug.dbg('Return reachable: %s', r) break return context_set
def get_return_values(self, check_yields=False): funcdef = self.tree_node if funcdef.type == 'lambdef': return self.evaluator.eval_element(self, funcdef.children[-1]) if check_yields: types = set() returns = funcdef.iter_yield_exprs() else: returns = funcdef.iter_return_stmts() types = set(docstrings.infer_return_types(self.function_context)) types |= set(pep0484.infer_return_types(self.function_context)) for r in returns: check = flow_analysis.reachability_check(self, funcdef, r) if check is flow_analysis.UNREACHABLE: debug.dbg('Return unreachable: %s', r) else: if check_yields: types |= set(self._eval_yield(r)) else: types |= self.eval_node(r.children[1]) if check is flow_analysis.REACHABLE: debug.dbg('Return reachable: %s', r) break return types
def get_return_values(self, check_yields=False): funcdef = self.tree_node if funcdef.type == 'lambdef': return self.evaluator.eval_element(self, funcdef.children[-1]) if check_yields: types = set() returns = get_yield_exprs(self.evaluator, funcdef) else: returns = funcdef.iter_return_stmts() types = set(docstrings.infer_return_types(self.function_context)) types |= set(pep0484.infer_return_types(self.function_context)) for r in returns: check = flow_analysis.reachability_check(self, funcdef, r) if check is flow_analysis.UNREACHABLE: debug.dbg('Return unreachable: %s', r) else: if check_yields: types |= set(self._eval_yield(r)) else: try: children = r.children except AttributeError: types.add(compiled.create(self.evaluator, None)) else: types |= self.eval_node(children[1]) if check is flow_analysis.REACHABLE: debug.dbg('Return reachable: %s', r) break return types
def _execute_function(self, params): from jedi.evaluate import docstrings from jedi.evaluate.compiled import builtin_from_name if self.api_type != 'function': return for name in self._parse_function_doc()[1].split(): try: # TODO wtf is this? this is exactly the same as the thing # below. It uses getattr as well. self.evaluator.builtins_module.access_handle.getattr(name) except AttributeError: continue else: bltn_obj = builtin_from_name(self.evaluator, name) for result in bltn_obj.execute(params): yield result for type_ in docstrings.infer_return_types(self): yield type_
def _execute_function(self, params): from jedi.evaluate import docstrings if self.type != 'funcdef': return for name in self._parse_function_doc()[1].split(): try: bltn_obj = getattr(_builtins, name) except AttributeError: continue else: if bltn_obj is None: # We want to evaluate everything except None. # TODO do we? continue bltn_obj = create(self.evaluator, bltn_obj) for result in self.evaluator.execute(bltn_obj, params): yield result for type_ in docstrings.infer_return_types(self): yield type_
def get_return_values(self, check_yields=False): funcdef = self.tree_node if funcdef.type == 'lambdef': return self.eval_node(funcdef.children[-1]) if check_yields: context_set = NO_CONTEXTS returns = get_yield_exprs(self.evaluator, funcdef) else: returns = funcdef.iter_return_stmts() from jedi.evaluate.gradual.annotation import infer_return_types context_set = infer_return_types(self) if context_set: # If there are annotations, prefer them over anything else. # This will make it faster. return context_set context_set |= docstrings.infer_return_types(self.function_context) for r in returns: check = flow_analysis.reachability_check(self, funcdef, r) if check is flow_analysis.UNREACHABLE: debug.dbg('Return unreachable: %s', r) else: if check_yields: context_set |= ContextSet.from_sets( lazy_context.infer() for lazy_context in self._get_yield_lazy_context(r)) else: try: children = r.children except AttributeError: ctx = compiled.builtin_from_name( self.evaluator, u'None') context_set |= ContextSet([ctx]) else: context_set |= self.eval_node(children[1]) if check is flow_analysis.REACHABLE: debug.dbg('Return reachable: %s', r) break return context_set