forked from VimPlug/jedi
Fix some more await things
This commit is contained in:
@@ -455,8 +455,10 @@ if py_version >= 35:
|
|||||||
CoroutineType = type(_coroutine)
|
CoroutineType = type(_coroutine)
|
||||||
_coroutine.close() # Prevent ResourceWarning
|
_coroutine.close() # Prevent ResourceWarning
|
||||||
"""), 'blub', 'exec'))
|
"""), 'blub', 'exec'))
|
||||||
|
_coroutine_wrapper = _coroutine.__await__()
|
||||||
else:
|
else:
|
||||||
_coroutine = None
|
_coroutine = None
|
||||||
|
_coroutine_wrapper = None
|
||||||
|
|
||||||
if py_version >= 36:
|
if py_version >= 36:
|
||||||
exec(compile(dedent("""
|
exec(compile(dedent("""
|
||||||
@@ -475,6 +477,7 @@ class _SPECIAL_OBJECTS(object):
|
|||||||
GENERATOR_OBJECT = _a_generator(1.0)
|
GENERATOR_OBJECT = _a_generator(1.0)
|
||||||
BUILTINS = builtins
|
BUILTINS = builtins
|
||||||
COROUTINE = _coroutine
|
COROUTINE = _coroutine
|
||||||
|
COROUTINE_WRAPPER = _coroutine_wrapper
|
||||||
ASYNC_GENERATOR = _async_generator
|
ASYNC_GENERATOR = _async_generator
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
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):
|
||||||
def __init__(self, evaluator, func_execution_context):
|
def __init__(self, evaluator, func_execution_context):
|
||||||
super(AsyncBase, self).__init__(evaluator)
|
super(AsyncBase, self).__init__(evaluator)
|
||||||
self._func_execution_context = func_execution_context
|
self.func_execution_context = func_execution_context
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def name(self):
|
def name(self):
|
||||||
return self.get_builtin_object().py__name__()
|
return self.get_object().name
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return "<%s of %s>" % (type(self).__name__, self._func_execution_context)
|
return "<%s of %s>" % (type(self).__name__, self.func_execution_context)
|
||||||
|
|
||||||
|
|
||||||
class Coroutine(AsyncBase):
|
class Coroutine(AsyncBase):
|
||||||
@@ -19,7 +20,14 @@ class Coroutine(AsyncBase):
|
|||||||
|
|
||||||
@publish_method('__await__')
|
@publish_method('__await__')
|
||||||
def _await(self):
|
def _await(self):
|
||||||
return self._func_execution_context.get_return_values()
|
return ContextSet(CoroutineWrapper(self.evaluator, self.func_execution_context))
|
||||||
|
|
||||||
|
|
||||||
|
class CoroutineWrapper(AsyncBase):
|
||||||
|
special_object_identifier = u'COROUTINE_WRAPPER'
|
||||||
|
|
||||||
|
def py__stop_iteration_returns(self):
|
||||||
|
return self.func_execution_context.get_return_values()
|
||||||
|
|
||||||
|
|
||||||
class AsyncGenerator(AsyncBase):
|
class AsyncGenerator(AsyncBase):
|
||||||
|
|||||||
@@ -50,6 +50,18 @@ def _limit_context_infers(func):
|
|||||||
return wrapper
|
return wrapper
|
||||||
|
|
||||||
|
|
||||||
|
def _py__stop_iteration_returns(generators):
|
||||||
|
results = ContextSet()
|
||||||
|
for generator in generators:
|
||||||
|
try:
|
||||||
|
method = generator.py__stop_iteration_returns
|
||||||
|
except AttributeError:
|
||||||
|
debug.warning('%s is not actually a generator', generator)
|
||||||
|
else:
|
||||||
|
results |= method()
|
||||||
|
return results
|
||||||
|
|
||||||
|
|
||||||
@debug.increase_indent
|
@debug.increase_indent
|
||||||
@_limit_context_infers
|
@_limit_context_infers
|
||||||
def eval_node(context, element):
|
def eval_node(context, element):
|
||||||
@@ -94,7 +106,8 @@ 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 await_context_set.execute_evaluated()
|
context_set = ContextSet()
|
||||||
|
return _py__stop_iteration_returns(await_context_set.execute_evaluated())
|
||||||
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.
|
||||||
@@ -129,15 +142,7 @@ def eval_node(context, element):
|
|||||||
# 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)
|
||||||
results = ContextSet()
|
return _py__stop_iteration_returns(generators)
|
||||||
for generator in generators:
|
|
||||||
try:
|
|
||||||
method = generator.py__stop_iteration_returns
|
|
||||||
except AttributeError:
|
|
||||||
debug.warning('%s is not actually a generator', generator)
|
|
||||||
else:
|
|
||||||
results |= method()
|
|
||||||
return results
|
|
||||||
|
|
||||||
# Generator.send() is not implemented.
|
# Generator.send() is not implemented.
|
||||||
return NO_CONTEXTS
|
return NO_CONTEXTS
|
||||||
@@ -326,7 +331,7 @@ def eval_or_test(context, or_test):
|
|||||||
# Otherwise continue, because of uncertainty.
|
# Otherwise continue, because of uncertainty.
|
||||||
else:
|
else:
|
||||||
types = _eval_comparison(context.evaluator, context, types, operator,
|
types = _eval_comparison(context.evaluator, context, types, operator,
|
||||||
context.eval_node(right))
|
context.eval_node(right))
|
||||||
debug.dbg('eval_or_test types %s', types)
|
debug.dbg('eval_or_test types %s', types)
|
||||||
return types
|
return types
|
||||||
|
|
||||||
|
|||||||
@@ -24,8 +24,8 @@ async def y():
|
|||||||
argh = await x()
|
argh = await x()
|
||||||
#? int()
|
#? int()
|
||||||
argh
|
argh
|
||||||
#? int()
|
#? ['__next__']
|
||||||
x().__await__()
|
x().__await__().__next
|
||||||
return 2
|
return 2
|
||||||
|
|
||||||
async def x2():
|
async def x2():
|
||||||
@@ -51,8 +51,7 @@ class Awaitable:
|
|||||||
|
|
||||||
async def awaitable_test():
|
async def awaitable_test():
|
||||||
foo = await Awaitable()
|
foo = await Awaitable()
|
||||||
# TODO doesn't work yet.
|
#? str()
|
||||||
##? int()
|
|
||||||
foo
|
foo
|
||||||
|
|
||||||
# python >= 3.6
|
# python >= 3.6
|
||||||
|
|||||||
Reference in New Issue
Block a user