diff --git a/jedi/evaluate/compiled/access.py b/jedi/evaluate/compiled/access.py index 9fb3b076..daf3c513 100644 --- a/jedi/evaluate/compiled/access.py +++ b/jedi/evaluate/compiled/access.py @@ -447,14 +447,31 @@ def _is_class_instance(obj): return cls != type and not issubclass(cls, NOT_CLASS_TYPES) +if py_version >= 35: + async def _coroutine(): pass + _coroutine = _coroutine() + CoroutineType = type(_coroutine) + _coroutine.close() # Prevent ResourceWarning +else: + _coroutine = None + +if py_version >= 36: + async def _async_generator(): + yield + _async_generator = _async_generator() + AsyncGeneratorType = type(_async_generator) +else: + _async_generator = None + + class _SPECIAL_OBJECTS(object): FUNCTION_CLASS = types.FunctionType METHOD_CLASS = type(DirectObjectAccess.py__bool__) MODULE_CLASS = types.ModuleType GENERATOR_OBJECT = _a_generator(1.0) BUILTINS = builtins - COROUTINE_TYPE = getattr(types, 'CoroutineType', None) - ASYNC_GENERATOR_TYPE = getattr(types, 'AsyncGeneratorType', None) + COROUTINE = _coroutine + ASYNC_GENERATOR = _async_generator def get_special_object(evaluator, identifier): diff --git a/jedi/evaluate/context/asynchronous.py b/jedi/evaluate/context/asynchronous.py index 1061ebbf..8b82dc35 100644 --- a/jedi/evaluate/context/asynchronous.py +++ b/jedi/evaluate/context/asynchronous.py @@ -1,5 +1,4 @@ from jedi.evaluate.filters import publish_method, BuiltinOverwrite -from jedi.evaluate.base_context import ContextSet class AsyncBase(BuiltinOverwrite): @@ -16,7 +15,7 @@ class AsyncBase(BuiltinOverwrite): class Coroutine(AsyncBase): - special_object_identifier = u'COROUTINE_TYPE' + special_object_identifier = u'COROUTINE' @publish_method('__await__') def _await(self): @@ -25,11 +24,7 @@ class Coroutine(AsyncBase): class AsyncGenerator(AsyncBase): """Handling of `yield` functions.""" - special_object_identifier = u'ASYNC_GENERATOR_TYPE' - - @publish_method('__anext__') - def py__anext__(self): - return ContextSet.from_sets(lazy_context.infer() for lazy_context in self.py__aiter__()) + special_object_identifier = u'ASYNC_GENERATOR' def py__aiter__(self): return self._func_execution_context.get_yield_lazy_contexts(is_async=True) diff --git a/jedi/evaluate/context/iterable.py b/jedi/evaluate/context/iterable.py index baffedfc..d656e0b4 100644 --- a/jedi/evaluate/context/iterable.py +++ b/jedi/evaluate/context/iterable.py @@ -106,7 +106,7 @@ def comprehension_from_atom(evaluator, context, atom): class ComprehensionMixin(object): - def __init__(self, evaluator, defining_context, atom, is_async=False): + def __init__(self, evaluator, defining_context, atom): super(ComprehensionMixin, self).__init__(evaluator) self._defining_context = defining_context self._atom = atom diff --git a/test/completion/async_.py b/test/completion/async_.py index 95a98853..41d34140 100644 --- a/test/completion/async_.py +++ b/test/completion/async_.py @@ -41,6 +41,8 @@ async def wrapper(): #? ['__anext__'] asgen().__ane +#? [] +asgen().mro async def x2():