mirror of
https://github.com/davidhalter/jedi.git
synced 2025-12-07 14:34:31 +08:00
Getting more edget cases work in 3.6 for async
This commit is contained in:
@@ -447,14 +447,31 @@ def _is_class_instance(obj):
|
|||||||
return cls != type and not issubclass(cls, NOT_CLASS_TYPES)
|
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):
|
class _SPECIAL_OBJECTS(object):
|
||||||
FUNCTION_CLASS = types.FunctionType
|
FUNCTION_CLASS = types.FunctionType
|
||||||
METHOD_CLASS = type(DirectObjectAccess.py__bool__)
|
METHOD_CLASS = type(DirectObjectAccess.py__bool__)
|
||||||
MODULE_CLASS = types.ModuleType
|
MODULE_CLASS = types.ModuleType
|
||||||
GENERATOR_OBJECT = _a_generator(1.0)
|
GENERATOR_OBJECT = _a_generator(1.0)
|
||||||
BUILTINS = builtins
|
BUILTINS = builtins
|
||||||
COROUTINE_TYPE = getattr(types, 'CoroutineType', None)
|
COROUTINE = _coroutine
|
||||||
ASYNC_GENERATOR_TYPE = getattr(types, 'AsyncGeneratorType', None)
|
ASYNC_GENERATOR = _async_generator
|
||||||
|
|
||||||
|
|
||||||
def get_special_object(evaluator, identifier):
|
def get_special_object(evaluator, identifier):
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
from jedi.evaluate.filters import publish_method, BuiltinOverwrite
|
from jedi.evaluate.filters import publish_method, BuiltinOverwrite
|
||||||
from jedi.evaluate.base_context import ContextSet
|
|
||||||
|
|
||||||
|
|
||||||
class AsyncBase(BuiltinOverwrite):
|
class AsyncBase(BuiltinOverwrite):
|
||||||
@@ -16,7 +15,7 @@ class AsyncBase(BuiltinOverwrite):
|
|||||||
|
|
||||||
|
|
||||||
class Coroutine(AsyncBase):
|
class Coroutine(AsyncBase):
|
||||||
special_object_identifier = u'COROUTINE_TYPE'
|
special_object_identifier = u'COROUTINE'
|
||||||
|
|
||||||
@publish_method('__await__')
|
@publish_method('__await__')
|
||||||
def _await(self):
|
def _await(self):
|
||||||
@@ -25,11 +24,7 @@ class Coroutine(AsyncBase):
|
|||||||
|
|
||||||
class AsyncGenerator(AsyncBase):
|
class AsyncGenerator(AsyncBase):
|
||||||
"""Handling of `yield` functions."""
|
"""Handling of `yield` functions."""
|
||||||
special_object_identifier = u'ASYNC_GENERATOR_TYPE'
|
special_object_identifier = u'ASYNC_GENERATOR'
|
||||||
|
|
||||||
@publish_method('__anext__')
|
|
||||||
def py__anext__(self):
|
|
||||||
return ContextSet.from_sets(lazy_context.infer() for lazy_context in self.py__aiter__())
|
|
||||||
|
|
||||||
def py__aiter__(self):
|
def py__aiter__(self):
|
||||||
return self._func_execution_context.get_yield_lazy_contexts(is_async=True)
|
return self._func_execution_context.get_yield_lazy_contexts(is_async=True)
|
||||||
|
|||||||
@@ -106,7 +106,7 @@ def comprehension_from_atom(evaluator, context, atom):
|
|||||||
|
|
||||||
|
|
||||||
class ComprehensionMixin(object):
|
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)
|
super(ComprehensionMixin, self).__init__(evaluator)
|
||||||
self._defining_context = defining_context
|
self._defining_context = defining_context
|
||||||
self._atom = atom
|
self._atom = atom
|
||||||
|
|||||||
@@ -41,6 +41,8 @@ async def wrapper():
|
|||||||
|
|
||||||
#? ['__anext__']
|
#? ['__anext__']
|
||||||
asgen().__ane
|
asgen().__ane
|
||||||
|
#? []
|
||||||
|
asgen().mro
|
||||||
|
|
||||||
|
|
||||||
async def x2():
|
async def x2():
|
||||||
|
|||||||
Reference in New Issue
Block a user