mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 13:51:37 +00:00
[red-knot] Fix async function edge case for inference of call expressions (#13187)
This commit is contained in:
parent
0c23b868dc
commit
fae0573817
2 changed files with 28 additions and 4 deletions
|
@ -381,10 +381,14 @@ impl<'db> FunctionType<'db> {
|
||||||
panic!("Function type definition must have `DefinitionKind::Function`")
|
panic!("Function type definition must have `DefinitionKind::Function`")
|
||||||
};
|
};
|
||||||
|
|
||||||
function_stmt_node
|
function_stmt_node.returns.as_ref().map(|returns| {
|
||||||
.returns
|
if function_stmt_node.is_async {
|
||||||
.as_ref()
|
// TODO: generic `types.CoroutineType`!
|
||||||
.map(|returns| definition_expression_ty(db, definition, returns.as_ref()))
|
Type::Unknown
|
||||||
|
} else {
|
||||||
|
definition_expression_ty(db, definition, returns.as_ref())
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2834,6 +2834,26 @@ mod tests {
|
||||||
Ok(())
|
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]
|
#[test]
|
||||||
fn class_constructor_call_expression() -> anyhow::Result<()> {
|
fn class_constructor_call_expression() -> anyhow::Result<()> {
|
||||||
let mut db = setup_db();
|
let mut db = setup_db();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue