Skip to content

Commit 81cd438

Browse files
chriskrychocarljm
andauthored
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 <[email protected]>
1 parent 483748c commit 81cd438

File tree

1 file changed

+19
-2
lines changed
  • crates/red_knot_python_semantic/src/types

1 file changed

+19
-2
lines changed

crates/red_knot_python_semantic/src/types/infer.rs

+19-2
Original file line numberDiff line numberDiff line change
@@ -1337,8 +1337,7 @@ impl<'db> TypeInferenceBuilder<'db> {
13371337
&mut self,
13381338
_literal: &ast::ExprEllipsisLiteral,
13391339
) -> Type<'db> {
1340-
// TODO Ellipsis
1341-
Type::Unknown
1340+
builtins_symbol_ty_by_name(self.db, "Ellipsis")
13421341
}
13431342

13441343
fn infer_tuple_expression(&mut self, tuple: &ast::ExprTuple) -> Type<'db> {
@@ -2470,6 +2469,24 @@ mod tests {
24702469
Ok(())
24712470
}
24722471

2472+
#[test]
2473+
fn ellipsis_type() -> anyhow::Result<()> {
2474+
let mut db = setup_db();
2475+
2476+
db.write_dedented(
2477+
"src/a.py",
2478+
"
2479+
x = ...
2480+
",
2481+
)?;
2482+
2483+
// TODO: update this once `infer_ellipsis_literal_expression` correctly
2484+
// infers `types.EllipsisType`.
2485+
assert_public_ty(&db, "src/a.py", "x", "Unknown | Literal[EllipsisType]");
2486+
2487+
Ok(())
2488+
}
2489+
24732490
#[test]
24742491
fn resolve_union() -> anyhow::Result<()> {
24752492
let mut db = setup_db();

0 commit comments

Comments
 (0)