mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 14:21:24 +00:00
correct signature of assert_type
This commit is contained in:
parent
0babd8d9d4
commit
49661f294a
3 changed files with 20 additions and 19 deletions
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
||||||
|
|
|
@ -4192,20 +4192,26 @@ impl<'db> Type<'db> {
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|
||||||
Some(KnownFunction::AssertType) => Binding::single(
|
Some(KnownFunction::AssertType) => {
|
||||||
|
let val_ty =
|
||||||
|
BoundTypeVarInstance::synthetic(db, "T", TypeVarVariance::Invariant);
|
||||||
|
|
||||||
|
Binding::single(
|
||||||
self,
|
self,
|
||||||
Signature::new(
|
Signature::new_generic(
|
||||||
|
Some(GenericContext::from_typevar_instances(db, [val_ty])),
|
||||||
Parameters::new([
|
Parameters::new([
|
||||||
Parameter::positional_only(Some(Name::new_static("value")))
|
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")))
|
Parameter::positional_only(Some(Name::new_static("type")))
|
||||||
.type_form()
|
.type_form()
|
||||||
.with_annotated_type(Type::any()),
|
.with_annotated_type(Type::any()),
|
||||||
]),
|
]),
|
||||||
Some(Type::none(db)),
|
Some(Type::TypeVar(val_ty)),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
.into(),
|
.into()
|
||||||
|
}
|
||||||
|
|
||||||
Some(KnownFunction::AssertNever) => {
|
Some(KnownFunction::AssertNever) => {
|
||||||
Binding::single(
|
Binding::single(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue