forked from VimPlug/jedi
Fix generator return issues
This commit is contained in:
@@ -57,12 +57,19 @@ class GeneratorBase(BuiltinOverwrite, IterableMixin):
|
|||||||
.execute_annotation()
|
.execute_annotation()
|
||||||
return generator
|
return generator
|
||||||
|
|
||||||
|
@publish_method('__iter__')
|
||||||
|
def py__iter__(self):
|
||||||
|
return ContextSet([self])
|
||||||
|
|
||||||
@publish_method('send')
|
@publish_method('send')
|
||||||
@publish_method('next', python_version_match=2)
|
@publish_method('next', python_version_match=2)
|
||||||
@publish_method('__next__', python_version_match=3)
|
@publish_method('__next__', python_version_match=3)
|
||||||
def py__next__(self):
|
def py__next__(self):
|
||||||
return ContextSet.from_sets(lazy_context.infer() for lazy_context in self.py__iter__())
|
return ContextSet.from_sets(lazy_context.infer() for lazy_context in self.py__iter__())
|
||||||
|
|
||||||
|
def py__stop_iteration_returns(self):
|
||||||
|
return ContextSet([compiled.builtin_from_name(self.evaluator, u'None')])
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
return compiled.CompiledContextName(self, 'generator')
|
return compiled.CompiledContextName(self, 'generator')
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ contexts.
|
|||||||
from jedi._compatibility import unicode
|
from jedi._compatibility import unicode
|
||||||
from jedi import debug
|
from jedi import debug
|
||||||
from jedi.evaluate.cache import evaluator_method_cache
|
from jedi.evaluate.cache import evaluator_method_cache
|
||||||
from jedi.evaluate.compiled import builtin_from_name, CompiledObject
|
from jedi.evaluate.compiled import builtin_from_name
|
||||||
from jedi.evaluate.base_context import ContextSet, NO_CONTEXTS, Context, \
|
from jedi.evaluate.base_context import ContextSet, NO_CONTEXTS, Context, \
|
||||||
iterator_to_context_set, HelperContextMixin, ContextWrapper
|
iterator_to_context_set, HelperContextMixin, ContextWrapper
|
||||||
from jedi.evaluate.lazy_context import LazyKnownContexts, LazyKnownContext
|
from jedi.evaluate.lazy_context import LazyKnownContexts, LazyKnownContext
|
||||||
@@ -17,7 +17,7 @@ from jedi.evaluate.filters import FilterWrapper, NameWrapper, \
|
|||||||
AbstractTreeName, AbstractNameDefinition, ContextName
|
AbstractTreeName, AbstractNameDefinition, ContextName
|
||||||
from jedi.evaluate.helpers import is_string
|
from jedi.evaluate.helpers import is_string
|
||||||
from jedi.evaluate.imports import Importer
|
from jedi.evaluate.imports import Importer
|
||||||
from jedi.evaluate.context import ClassContext
|
from jedi.evaluate.context.klass import py__mro__, ClassContext
|
||||||
|
|
||||||
_PROXY_CLASS_TYPES = 'Tuple Generic Protocol Callable Type'.split()
|
_PROXY_CLASS_TYPES = 'Tuple Generic Protocol Callable Type'.split()
|
||||||
_TYPE_ALIAS_TYPES = {
|
_TYPE_ALIAS_TYPES = {
|
||||||
@@ -607,11 +607,13 @@ class LazyAnnotatedBaseClass(object):
|
|||||||
|
|
||||||
class InstanceWrapper(ContextWrapper):
|
class InstanceWrapper(ContextWrapper):
|
||||||
def py__stop_iteration_returns(self):
|
def py__stop_iteration_returns(self):
|
||||||
cls = self._wrapped_context.class_context
|
for cls in py__mro__(self._wrapped_context.class_context):
|
||||||
if cls.py__name__() == 'Generator':
|
if cls.py__name__() == 'Generator':
|
||||||
given_types = cls.get_given_types()
|
given_types = cls.get_given_types()
|
||||||
try:
|
try:
|
||||||
return given_types[2].execute_annotation()
|
return given_types[2].execute_annotation()
|
||||||
except IndexError:
|
except IndexError:
|
||||||
pass
|
pass
|
||||||
|
elif cls.py__name__() == 'Iterator':
|
||||||
|
return ContextSet([builtin_from_name(self.evaluator, u'None')])
|
||||||
return self._wrapped_context.py__stop_iteration_returns()
|
return self._wrapped_context.py__stop_iteration_returns()
|
||||||
|
|||||||
@@ -100,7 +100,7 @@ def eval_node(context, element):
|
|||||||
await_context_set = context_set.py__getattribute__(u"__await__")
|
await_context_set = context_set.py__getattribute__(u"__await__")
|
||||||
if not await_context_set:
|
if not await_context_set:
|
||||||
debug.warning('Tried to run py__await__ on context %s', context)
|
debug.warning('Tried to run py__await__ on context %s', context)
|
||||||
return _py__stop_iteration_returns(await_context_set.execute_evaluated())
|
return await_context_set.execute_evaluated().py__stop_iteration_returns()
|
||||||
return context_set
|
return context_set
|
||||||
elif typ in ('testlist_star_expr', 'testlist',):
|
elif typ in ('testlist_star_expr', 'testlist',):
|
||||||
# The implicit tuple in statements.
|
# The implicit tuple in statements.
|
||||||
@@ -136,8 +136,9 @@ def eval_node(context, element):
|
|||||||
if len(element.children) and element.children[1].type == 'yield_arg':
|
if len(element.children) and element.children[1].type == 'yield_arg':
|
||||||
# Implies that it's a yield from.
|
# Implies that it's a yield from.
|
||||||
element = element.children[1].children[1]
|
element = element.children[1].children[1]
|
||||||
generators = context.eval_node(element)
|
generators = context.eval_node(element) \
|
||||||
return _py__stop_iteration_returns(generators)
|
.py__getattribute__('__iter__').execute_evaluated()
|
||||||
|
return generators.py__stop_iteration_returns()
|
||||||
|
|
||||||
# Generator.send() is not implemented.
|
# Generator.send() is not implemented.
|
||||||
return NO_CONTEXTS
|
return NO_CONTEXTS
|
||||||
|
|||||||
Reference in New Issue
Block a user