correct signature of assert_type

This commit is contained in:
Ibraheem Ahmed 2025-09-29 15:17:56 -04:00
parent 0babd8d9d4
commit 49661f294a
3 changed files with 20 additions and 19 deletions

View file

@ -1695,10 +1695,8 @@ class T(TypedDict):
@overload
def f(a: list[T], b: int) -> int: ...
@overload
def f(a: list[dict[str, int]], b: str) -> str: ...
def f(a: list[dict[str, int]] | list[T], b: int | str) -> int | str:
return 1
@ -1723,10 +1721,8 @@ class T(TypedDict):
@overload
def f(a: T, b: int) -> int: ...
@overload
def f(a: dict[str, int], b: str) -> str: ...
def f(a: T | dict[str, int], b: int | str) -> int | str:
return 1

View file

@ -269,7 +269,6 @@ def _(flag: bool):
else:
def f(x: dict[str, int]) -> int:
return 1
x = f({"x": 1})
reveal_type(x) # revealed: int

View file

@ -4192,20 +4192,26 @@ impl<'db> Type<'db> {
.into()
}
Some(KnownFunction::AssertType) => Binding::single(
Some(KnownFunction::AssertType) => {
let val_ty =
BoundTypeVarInstance::synthetic(db, "T", TypeVarVariance::Invariant);
Binding::single(
self,
Signature::new(
Signature::new_generic(
Some(GenericContext::from_typevar_instances(db, [val_ty])),
Parameters::new([
Parameter::positional_only(Some(Name::new_static("value")))
.with_annotated_type(Type::any()),
.with_annotated_type(Type::TypeVar(val_ty)),
Parameter::positional_only(Some(Name::new_static("type")))
.type_form()
.with_annotated_type(Type::any()),
]),
Some(Type::none(db)),
Some(Type::TypeVar(val_ty)),
),
)
.into(),
.into()
}
Some(KnownFunction::AssertNever) => {
Binding::single(