Beispiel #1
0
    def infer_function_execution(self, function_execution):
        """
        Created to be used by inheritance.
        """
        is_coroutine = self.tree_node.parent.type == 'async_stmt'
        is_generator = bool(get_yield_exprs(self.evaluator, self.tree_node))

        if is_coroutine:
            if is_generator:
                if self.evaluator.environment.version_info < (3, 6):
                    return NO_CONTEXTS
                return ContextSet(
                    asynchronous.AsyncGenerator(self.evaluator,
                                                function_execution))
            else:
                if self.evaluator.environment.version_info < (3, 5):
                    return NO_CONTEXTS
                return ContextSet(
                    asynchronous.Coroutine(self.evaluator, function_execution))
        else:
            if is_generator:
                return ContextSet(
                    iterable.Generator(self.evaluator, function_execution))
            else:
                return function_execution.get_return_values()
Beispiel #2
0
 def infer_function_execution(self, function_execution):
     """
     Created to be used by inheritance.
     """
     yield_exprs = get_yield_exprs(self.evaluator, self.tree_node)
     if yield_exprs:
         return ContextSet(
             iterable.Generator(self.evaluator, function_execution))
     else:
         return function_execution.get_return_values()
Beispiel #3
0
    def infer(self):
        """
        Created to be used by inheritance.
        """
        evaluator = self.evaluator
        is_coroutine = self.tree_node.parent.type in ('async_stmt',
                                                      'async_funcdef')
        is_generator = bool(get_yield_exprs(evaluator, self.tree_node))
        from jedi.evaluate.gradual.typing import GenericClass

        if is_coroutine:
            if is_generator:
                if evaluator.environment.version_info < (3, 6):
                    return NO_CONTEXTS
                async_generator_classes = evaluator.typing_module \
                    .py__getattribute__('AsyncGenerator')

                yield_contexts = self.merge_yield_contexts(is_async=True)
                # The contravariant doesn't seem to be defined.
                generics = (yield_contexts.py__class__(), NO_CONTEXTS)
                return ContextSet(
                    # In Python 3.6 AsyncGenerator is still a class.
                    GenericClass(c, generics)
                    for c in async_generator_classes).execute_annotation()
            else:
                if evaluator.environment.version_info < (3, 5):
                    return NO_CONTEXTS
                async_classes = evaluator.typing_module.py__getattribute__(
                    'Coroutine')
                return_contexts = self.get_return_values()
                # Only the first generic is relevant.
                generics = (return_contexts.py__class__(), NO_CONTEXTS,
                            NO_CONTEXTS)
                return ContextSet(
                    GenericClass(c, generics)
                    for c in async_classes).execute_annotation()
        else:
            if is_generator:
                return ContextSet([iterable.Generator(evaluator, self)])
            else:
                return self.get_return_values()