Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ h: list[list[int]] = [[], [42]]
reveal_type(h) # revealed: list[list[int]]

i: list[typing.Any] = [1, 2, "3", ([4],)]
reveal_type(i) # revealed: list[Any | int | str | tuple[list[Unknown | int]]]
reveal_type(i) # revealed: list[Any]

j: list[tuple[str | int, ...]] = [(1, 2), ("foo", "bar"), ()]
reveal_type(j) # revealed: list[tuple[str | int, ...]]
Expand All @@ -123,7 +123,7 @@ k: list[tuple[list[int], ...]] = [([],), ([1, 2], [3, 4]), ([5], [6], [7])]
reveal_type(k) # revealed: list[tuple[list[int], ...]]

l: tuple[list[int], *tuple[list[typing.Any], ...], list[str]] = ([1, 2, 3], [4, 5, 6], [7, 8, 9], ["10", "11", "12"])
reveal_type(l) # revealed: tuple[list[int], list[Any | int], list[Any | int], list[str]]
reveal_type(l) # revealed: tuple[list[int], list[Any], list[Any], list[str]]

type IntList = list[int]

Expand Down Expand Up @@ -187,7 +187,7 @@ h: list[list[int]] | None = [[], [42]]
reveal_type(h) # revealed: list[list[int]]

i: list[typing.Any] | None = [1, 2, "3", ([4],)]
reveal_type(i) # revealed: list[Any | int | str | tuple[list[Unknown | int]]]
reveal_type(i) # revealed: list[Any]

j: list[tuple[str | int, ...]] | None = [(1, 2), ("foo", "bar"), ()]
reveal_type(j) # revealed: list[tuple[str | int, ...]]
Expand All @@ -196,7 +196,7 @@ k: list[tuple[list[int], ...]] | None = [([],), ([1, 2], [3, 4]), ([5], [6], [7]
reveal_type(k) # revealed: list[tuple[list[int], ...]]

l: tuple[list[int], *tuple[list[typing.Any], ...], list[str]] | None = ([1, 2, 3], [4, 5, 6], [7, 8, 9], ["10", "11", "12"])
reveal_type(l) # revealed: tuple[list[int], list[Any | int], list[Any | int], list[str]]
reveal_type(l) # revealed: tuple[list[int], list[Any], list[Any], list[str]]

type IntList = list[int]

Expand Down Expand Up @@ -282,7 +282,7 @@ reveal_type(k) # revealed: list[Literal[1, 2, 3]]
type Y[T] = list[T]

l: Y[Y[Literal[1]]] = [[1]]
reveal_type(l) # revealed: list[list[Literal[1]]]
reveal_type(l) # revealed: list[Y[Literal[1]]]

m: list[tuple[Literal[1], Literal[2], Literal[3]]] = [(1, 2, 3)]
reveal_type(m) # revealed: list[tuple[Literal[1], Literal[2], Literal[3]]]
Expand Down
10 changes: 9 additions & 1 deletion crates/ty_python_semantic/src/types/display.rs
Original file line number Diff line number Diff line change
Expand Up @@ -593,7 +593,15 @@ impl Display for DisplayRepresentation<'_> {
.0
.display_with(self.db, self.settings.clone())
.fmt(f),
Type::TypeAlias(alias) => f.write_str(alias.name(self.db)),
Type::TypeAlias(alias) => {
f.write_str(alias.name(self.db))?;
match alias.specialization(self.db) {
None => Ok(()),
Some(specialization) => specialization
.display_short(self.db, TupleSpecialization::No, self.settings.clone())
.fmt(f),
}
}
}
}
}
Expand Down
7 changes: 7 additions & 0 deletions crates/ty_python_semantic/src/types/infer/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6146,6 +6146,13 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {

let inferred_elt_ty = self.get_or_infer_expression(elt, elt_tcx);

// Simplify the inference based on the declared type of the element.
if let Some(elt_tcx) = elt_tcx.annotation {
if inferred_elt_ty.is_assignable_to(self.db(), elt_tcx) {
continue;
}
}

// Convert any element literals to their promoted type form to avoid excessively large
// unions for large nested list literals, which the constraint solver struggles with.
let inferred_elt_ty = inferred_elt_ty.promote_literals(self.db(), elt_tcx);
Expand Down
Loading