Skip to content

Commit

Permalink
red-knot: infer and display ellipsis type (#13124)
Browse files Browse the repository at this point in the history
## 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]>
  • Loading branch information
chriskrycho and carljm committed Aug 27, 2024
1 parent 483748c commit 81cd438
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions crates/red_knot_python_semantic/src/types/infer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 81cd438

Please sign in to comment.