mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-06 22:14:27 +08:00
Yield expressions are now separate form ReturnStmt.
This commit is contained in:
@@ -512,7 +512,7 @@ class Function(use_metaclass(CachedMetaClass, Wrapper)):
|
||||
|
||||
@Python3Method
|
||||
def py__call__(self, evaluator, params):
|
||||
if self.is_generator:
|
||||
if self.base.is_generator():
|
||||
return [iterable.Generator(evaluator, self, params)]
|
||||
else:
|
||||
return FunctionExecution(evaluator, self, params).get_return_types()
|
||||
|
||||
@@ -78,7 +78,7 @@ def convert(grammar, raw_node):
|
||||
'continue_stmt': pr.KeywordStatement,
|
||||
'return_stmt': pr.ReturnStmt,
|
||||
'raise_stmt': pr.KeywordStatement,
|
||||
'yield_stmt': pr.ReturnStmt,
|
||||
'yield_expr': pr.YieldExpr,
|
||||
'del_stmt': pr.KeywordStatement,
|
||||
'pass_stmt': pr.KeywordStatement,
|
||||
'global_stmt': pr.GlobalStmt,
|
||||
|
||||
@@ -441,15 +441,13 @@ class Scope(Simple, DocstringMixin):
|
||||
:param start_pos: The position (line and column) of the scope.
|
||||
:type start_pos: tuple(int, int)
|
||||
"""
|
||||
__slots__ = ('imports', '_doc_token', 'asserts', 'names_dict',
|
||||
'is_generator')
|
||||
__slots__ = ('imports', '_doc_token', 'asserts', 'names_dict')
|
||||
|
||||
def __init__(self, children):
|
||||
super(Scope, self).__init__(children)
|
||||
self.imports = []
|
||||
self._doc_token = None
|
||||
self.asserts = []
|
||||
self.is_generator = False
|
||||
|
||||
@property
|
||||
def returns(self):
|
||||
@@ -784,6 +782,14 @@ class Function(ClassOrFunc):
|
||||
else:
|
||||
return [Param(node[0], self)]
|
||||
|
||||
@property
|
||||
def yields(self):
|
||||
# TODO This is incorrect, yields are also possible in a statement.
|
||||
return self._search_in_scope(YieldExpr)
|
||||
|
||||
def is_generator(self):
|
||||
return bool(self.yields)
|
||||
|
||||
def annotation(self):
|
||||
try:
|
||||
return self.children[6] # 6th element: def foo(...) -> bar
|
||||
@@ -1074,6 +1080,10 @@ class ReturnStmt(Simple):
|
||||
pass
|
||||
|
||||
|
||||
class YieldExpr(Simple):
|
||||
pass
|
||||
|
||||
|
||||
class Statement(Simple, DocstringMixin):
|
||||
"""
|
||||
This is the class for all the possible statements. Which means, this class
|
||||
|
||||
Reference in New Issue
Block a user