[ty] Improve disambiguation of class names in diagnostics (#20603)

This commit is contained in:
Alex Waygood 2025-09-29 11:43:11 +01:00 committed by GitHub
parent 81f43a1fc8
commit 3f640dacd4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 243 additions and 154 deletions

View file

@ -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
```
@ -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(),)
```

View file

@ -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()
```