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 @@ -43,8 +43,7 @@ import b
df: a.DataFrame = b.DataFrame() # error: [invalid-assignment] "Object of type `b.DataFrame` is not assignable to `a.DataFrame`"

def _(dfs: list[b.DataFrame]):
# TODO should be"Object of type `list[b.DataFrame]` is not assignable to `list[a.DataFrame]`
# error: [invalid-assignment] "Object of type `list[DataFrame]` is not assignable to `list[DataFrame]`"
# error: [invalid-assignment] "Object of type `list[b.DataFrame]` is not assignable to `list[a.DataFrame]`"
dataframes: list[a.DataFrame] = dfs
```

Expand Down Expand Up @@ -228,3 +227,21 @@ from typing import TypedDict
class Person(TypedDict):
name: bytes
```

## Tuple specializations

`module.py`:

```py
class Model: ...
```

```py
class Model: ...

def get_models_tuple() -> tuple[Model]:
from module import Model

# error: [invalid-return-type] "Return type does not match returned value: expected `tuple[mdtest_snippet.Model]`, found `tuple[module.Model]`"
return (Model(),)
```
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ class A: ...

def f(x: A):
# TODO: no error
# error: [invalid-assignment] "Object of type `A | A` is not assignable to `A`"
# error: [invalid-assignment] "Object of type `mdtest_snippet.A | mdtest_snippet.A` is not assignable to `mdtest_snippet.A`"
x = A()
```

Expand Down
6 changes: 5 additions & 1 deletion crates/ty_python_semantic/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7065,7 +7065,11 @@ impl<'db> KnownInstanceType<'db> {
if let Some(specialization) = alias.specialization(self.db) {
f.write_str(alias.name(self.db))?;
specialization
.display_short(self.db, TupleSpecialization::No)
.display_short(
self.db,
TupleSpecialization::No,
DisplaySettings::default(),
)
.fmt(f)
} else {
f.write_str("typing.TypeAliasType")
Expand Down
6 changes: 3 additions & 3 deletions crates/ty_python_semantic/src/types/diagnostic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1986,7 +1986,7 @@ pub(super) fn report_invalid_assignment<'db>(
target_ty,
format_args!(
"Object of type `{}` is not assignable to `{}`",
source_ty.display_with(context.db(), settings),
source_ty.display_with(context.db(), settings.clone()),
target_ty.display_with(context.db(), settings)
),
);
Expand Down Expand Up @@ -2068,8 +2068,8 @@ pub(super) fn report_invalid_return_type(
let mut diag = builder.into_diagnostic("Return type does not match returned value");
diag.set_primary_message(format_args!(
"expected `{expected_ty}`, found `{actual_ty}`",
expected_ty = expected_ty.display_with(context.db(), settings),
actual_ty = actual_ty.display_with(context.db(), settings),
expected_ty = expected_ty.display_with(context.db(), settings.clone()),
actual_ty = actual_ty.display_with(context.db(), settings.clone()),
));
diag.annotate(
Annotation::secondary(return_type_span).message(format_args!(
Expand Down
Loading
Loading