mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 13:51:37 +00:00
red-knot: infer and display ellipsis type (#13124)
## Summary Just what it says on the tin: adds basic `EllipsisType` inference for any time `...` appears in the AST. ## Test Plan Test that `x = ...` produces exactly what we would expect. --------- Co-authored-by: Carl Meyer <carl@oddbird.net>
This commit is contained in:
parent
483748c188
commit
81cd438d88
1 changed files with 19 additions and 2 deletions
|
@ -1337,8 +1337,7 @@ impl<'db> TypeInferenceBuilder<'db> {
|
||||||
&mut self,
|
&mut self,
|
||||||
_literal: &ast::ExprEllipsisLiteral,
|
_literal: &ast::ExprEllipsisLiteral,
|
||||||
) -> Type<'db> {
|
) -> Type<'db> {
|
||||||
// TODO Ellipsis
|
builtins_symbol_ty_by_name(self.db, "Ellipsis")
|
||||||
Type::Unknown
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn infer_tuple_expression(&mut self, tuple: &ast::ExprTuple) -> Type<'db> {
|
fn infer_tuple_expression(&mut self, tuple: &ast::ExprTuple) -> Type<'db> {
|
||||||
|
@ -2470,6 +2469,24 @@ mod tests {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn ellipsis_type() -> anyhow::Result<()> {
|
||||||
|
let mut db = setup_db();
|
||||||
|
|
||||||
|
db.write_dedented(
|
||||||
|
"src/a.py",
|
||||||
|
"
|
||||||
|
x = ...
|
||||||
|
",
|
||||||
|
)?;
|
||||||
|
|
||||||
|
// TODO: update this once `infer_ellipsis_literal_expression` correctly
|
||||||
|
// infers `types.EllipsisType`.
|
||||||
|
assert_public_ty(&db, "src/a.py", "x", "Unknown | Literal[EllipsisType]");
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn resolve_union() -> anyhow::Result<()> {
|
fn resolve_union() -> anyhow::Result<()> {
|
||||||
let mut db = setup_db();
|
let mut db = setup_db();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue