From 81cd438d883dafb7c51cf2ec9b8e8dcec5cf1f6b Mon Sep 17 00:00:00 2001 From: Chris Krycho Date: Tue, 27 Aug 2024 13:52:53 -0600 Subject: [PATCH] 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 --- .../src/types/infer.rs | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/crates/red_knot_python_semantic/src/types/infer.rs b/crates/red_knot_python_semantic/src/types/infer.rs index 67929cbfa9e1d..b1a915da23312 100644 --- a/crates/red_knot_python_semantic/src/types/infer.rs +++ b/crates/red_knot_python_semantic/src/types/infer.rs @@ -1337,8 +1337,7 @@ impl<'db> TypeInferenceBuilder<'db> { &mut self, _literal: &ast::ExprEllipsisLiteral, ) -> Type<'db> { - // TODO Ellipsis - Type::Unknown + builtins_symbol_ty_by_name(self.db, "Ellipsis") } fn infer_tuple_expression(&mut self, tuple: &ast::ExprTuple) -> Type<'db> { @@ -2470,6 +2469,24 @@ mod tests { 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] fn resolve_union() -> anyhow::Result<()> { let mut db = setup_db();