mirror of
https://github.com/astral-sh/ruff.git
synced 2025-10-01 22:31:23 +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
|
||||
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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -4192,20 +4192,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(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue