Skip to content

Commit 9f36264

Browse files
committed
support-coroutine-object-too
1 parent 5ac15f9 commit 9f36264

2 files changed

Lines changed: 31 additions & 1 deletion

File tree

IPython/core/guarded_eval.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -685,6 +685,16 @@ def _is_instance_attribute_assignment(
685685
)
686686

687687

688+
def _get_coroutine_attributes() -> dict[str, Optional[object]]:
689+
async def _dummy():
690+
return None
691+
692+
coro = _dummy()
693+
try:
694+
return {attr: getattr(coro, attr, None) for attr in dir(coro)}
695+
finally:
696+
coro.close()
697+
688698
def eval_node(node: Union[ast.AST, None], context: EvaluationContext):
689699
"""Evaluate AST node in provided context.
690700
@@ -974,7 +984,7 @@ def dummy_function(*args, **kwargs):
974984
awaited_type = (
975985
inferred_return if inferred_return is not None else return_type
976986
)
977-
coroutine_duck = ImpersonatingDuck()
987+
coroutine_duck = _Duck(attributes=_get_coroutine_attributes())
978988
coroutine_duck.__awaited_type__ = awaited_type
979989
return coroutine_duck
980990
if inferred_return is not NOT_EVALUATED:

tests/test_completer.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2296,6 +2296,26 @@ def _(expected):
22962296
),
22972297
"as_integer_ratio",
22982298
],
2299+
[
2300+
"\n".join(
2301+
[
2302+
"async def async_func():",
2303+
" return []",
2304+
"async_func().",
2305+
]
2306+
),
2307+
"cr_await",
2308+
],
2309+
[
2310+
"\n".join(
2311+
[
2312+
"async def async_func():",
2313+
" return []",
2314+
"(await async_func()).",
2315+
]
2316+
),
2317+
"append",
2318+
],
22992319
],
23002320
)
23012321
def test_undefined_variables(use_jedi, evaluation, code, insert_text):

0 commit comments

Comments
 (0)