From fae0573817bafb5d36616cbd2efb3d8f36c6108d Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Sun, 1 Sep 2024 01:58:35 +0100 Subject: [PATCH] [red-knot] Fix async function edge case for inference of call expressions (#13187) --- crates/red_knot_python_semantic/src/types.rs | 12 +++++++---- .../src/types/infer.rs | 20 +++++++++++++++++++ 2 files changed, 28 insertions(+), 4 deletions(-) diff --git a/crates/red_knot_python_semantic/src/types.rs b/crates/red_knot_python_semantic/src/types.rs index d7b9c8e91d4d3..8a9972bd6b289 100644 --- a/crates/red_knot_python_semantic/src/types.rs +++ b/crates/red_knot_python_semantic/src/types.rs @@ -381,10 +381,14 @@ impl<'db> FunctionType<'db> { panic!("Function type definition must have `DefinitionKind::Function`") }; - function_stmt_node - .returns - .as_ref() - .map(|returns| definition_expression_ty(db, definition, returns.as_ref())) + function_stmt_node.returns.as_ref().map(|returns| { + if function_stmt_node.is_async { + // TODO: generic `types.CoroutineType`! + Type::Unknown + } else { + definition_expression_ty(db, definition, returns.as_ref()) + } + }) } } diff --git a/crates/red_knot_python_semantic/src/types/infer.rs b/crates/red_knot_python_semantic/src/types/infer.rs index 5286fa0420073..2cd8ac2ed821d 100644 --- a/crates/red_knot_python_semantic/src/types/infer.rs +++ b/crates/red_knot_python_semantic/src/types/infer.rs @@ -2834,6 +2834,26 @@ mod tests { Ok(()) } + #[test] + fn basic_async_call_expression() -> anyhow::Result<()> { + let mut db = setup_db(); + + db.write_dedented( + "src/a.py", + " + async def get_int_async() -> int: + return 42 + + x = get_int_async() + ", + )?; + + // TODO: Generic `types.CoroutineType`! + assert_public_ty(&db, "src/a.py", "x", "Unknown"); + + Ok(()) + } + #[test] fn class_constructor_call_expression() -> anyhow::Result<()> { let mut db = setup_db();