Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

red-knot: infer and display ellipsis type #13124

Merged
merged 3 commits into from
Aug 27, 2024
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 22 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,10 @@ impl<'db> TypeInferenceBuilder<'db> {
&mut self,
_literal: &ast::ExprEllipsisLiteral,
) -> Type<'db> {
// TODO Ellipsis
Type::Unknown
// TODO: this does not currently resolve to `types.EllipsisType` as it
// should, and it needs support for sealed types (with a single member
// for singletons like this) as well (#12694).
carljm marked this conversation as resolved.
Show resolved Hide resolved
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 +2472,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
Loading