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

View file

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

View file

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