Getting more edget cases work in 3.6 for async

This commit is contained in:
Dave Halter
2018-02-21 01:11:59 +01:00
parent de5d7961e8
commit c1d06f4638
4 changed files with 24 additions and 10 deletions

View File

@@ -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):

View File

@@ -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)

View File

@@ -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

View File

@@ -41,6 +41,8 @@ async def wrapper():
#? ['__anext__']
asgen().__ane
#? []
asgen().mro
async def x2():