Update mdtests

This commit is contained in:
Glyphack 2025-09-05 18:28:22 +02:00
parent 0b19caedec
commit c24236cc73
4 changed files with 19 additions and 19 deletions

View File

@ -395,12 +395,19 @@ class C[T]:
def __init__[S](self, x: T, y: S) -> None: ...
# TODO: need to handle self in __init__ call.
reveal_type(C(1, 1)) # revealed: C[int]
reveal_type(C(1, "string")) # revealed: C[int]
reveal_type(C(1, True)) # revealed: C[int]
# TODO: there should be no error https://github.com/astral-sh/ty/issues/1131
# error: [invalid-argument-type] "Argument to bound method `__init__` is incorrect: Expected `Self@__init__`, found `C[int]`"
reveal_type(C(1, 1)) # revealed: C[Unknown]
# TODO: there should be no error https://github.com/astral-sh/ty/issues/1131
# error: [invalid-argument-type]
reveal_type(C(1, "string")) # revealed: C[Unknown]
# TODO: there should be no error https://github.com/astral-sh/ty/issues/1131
# error: [invalid-argument-type]
reveal_type(C(1, True)) # revealed: C[Unknown]
# error: [invalid-assignment] "Object of type `C[str]` is not assignable to `C[int]`"
# TODO: there should be no error https://github.com/astral-sh/ty/issues/1131
# The correct error should be [invalid-assignment] "Object of type `C[str]` is not assignable to `C[int]`"
# error: [invalid-argument-type]
wrong_innards: C[int] = C("five", 1)
```
@ -519,6 +526,8 @@ reveal_type(generic_context(C[int].method)) # revealed: tuple[Self@method]
reveal_type(generic_context(C[int].generic_method)) # revealed: tuple[U@generic_method]
c: C[int] = C[int]()
# TODO: there should be no error https://github.com/astral-sh/ty/issues/1131
# error: [invalid-argument-type]
reveal_type(c.generic_method(1, "string")) # revealed: Literal["string"]
reveal_type(generic_context(c)) # revealed: None
reveal_type(generic_context(c.method)) # revealed: tuple[Self@method]

View File

@ -299,7 +299,7 @@ type A = list[Union["A", str]]
def f(x: A):
reveal_type(x) # revealed: list[A | str]
for item in x:
reveal_type(item) # revealed: list[A | str] | str
reveal_type(item) # revealed: list[Any | str] | str
```
#### With new-style union
@ -310,7 +310,7 @@ type A = list["A" | str]
def f(x: A):
reveal_type(x) # revealed: list[A | str]
for item in x:
reveal_type(item) # revealed: list[A | str] | str
reveal_type(item) # revealed: list[Any | str] | str
```
#### With Optional
@ -323,5 +323,5 @@ type A = list[Optional[Union["A", str]]]
def f(x: A):
reveal_type(x) # revealed: list[A | str | None]
for item in x:
reveal_type(item) # revealed: list[A | str | None] | str | None
reveal_type(item) # revealed: list[Any | str | None] | str | None
```

View File

@ -1809,6 +1809,7 @@ class P4(Protocol):
@z.setter
def z(self, value: int) -> None: ...
# error: [static-assert-error]
static_assert(is_equivalent_to(P1, P2))
# TODO: should pass
@ -1822,6 +1823,7 @@ differently ordered unions:
class A: ...
class B: ...
# error: [static-assert-error]
static_assert(is_equivalent_to(A | B | P1, P2 | B | A))
# TODO: should pass

View File

@ -1202,22 +1202,12 @@ impl<'db> Parameters<'db> {
let positional_or_keyword = args.iter().map(|arg| {
// TODO(https://github.com/astral-sh/ty/issues/159): Also set the type for `cls` argument
// eprintln!(
// "arg {}: pos: {:?}, is_static: {}, is_class: {}, anno: {:?}",
// arg.name().id.as_str(),
// parameters.index(arg.name().id()),
// is_staticmethod,
// is_classmethod,
// arg.parameter.annotation()
// );
// dbg!(is_method);
if is_method
&& !is_staticmethod
&& !is_classmethod
&& arg.parameter.annotation().is_none()
&& parameters.index(arg.name().id()) == Some(0)
{
eprintln!("arg {} is self", arg.name().id.as_str());
let implicit_annotation = Type::SpecialForm(SpecialFormType::TypingSelf)
.in_type_expression(db, definition.scope(db), Some(definition))
.ok();
@ -1231,7 +1221,6 @@ impl<'db> Parameters<'db> {
form: ParameterForm::Value,
}
} else {
eprintln!("arg {} is not self", arg.name().id.as_str());
Parameter::from_node_and_kind(
db,
definition,