1
3
mirror of https://github.com/charliermarsh/ruff synced 2025-10-05 23:52:47 +02:00

correct signature of assert_type

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

View File

@@ -1675,10 +1675,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
@@ -1703,10 +1701,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

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