Fix value-position specializations
This commit is contained in:
@@ -462,19 +462,39 @@ expected:
|
||||
IntsOrNone = MyList[int] | None
|
||||
IntsOrStrs = Pair[int] | Pair[str]
|
||||
ListOfPairs = MyList[Pair[str]]
|
||||
ListOrTupleOfInts = ListOrTuple[int]
|
||||
AnnotatedInt = AnnotatedType[int]
|
||||
SubclassOfInt = MyType[int]
|
||||
# TODO: No error here
|
||||
# error: [too-many-positional-arguments] "Too many positional arguments: expected 1, got 2"
|
||||
# error: [invalid-type-form] "List literals are not allowed in this context in a type expression: Did you mean `list[int]`?"
|
||||
CallableIntToStr = MyCallable[[int], str]
|
||||
|
||||
reveal_type(IntsOrNone) # revealed: types.UnionType
|
||||
reveal_type(IntsOrStrs) # revealed: types.UnionType
|
||||
reveal_type(ListOfPairs) # revealed: <class 'list[tuple[str, str]]'>
|
||||
reveal_type(ListOrTupleOfInts) # revealed: types.UnionType
|
||||
reveal_type(AnnotatedInt) # revealed: <typing.Annotated special form>
|
||||
reveal_type(SubclassOfInt) # revealed: GenericAlias
|
||||
reveal_type(CallableIntToStr) # revealed: Unknown
|
||||
|
||||
def _(
|
||||
ints_or_none: IntsOrNone,
|
||||
ints_or_strs: IntsOrStrs,
|
||||
list_of_pairs: ListOfPairs,
|
||||
list_or_tuple_of_ints: ListOrTupleOfInts,
|
||||
annotated_int: AnnotatedInt,
|
||||
subclass_of_int: SubclassOfInt,
|
||||
callable_int_to_str: CallableIntToStr,
|
||||
):
|
||||
reveal_type(ints_or_none) # revealed: list[int] | None
|
||||
reveal_type(ints_or_strs) # revealed: tuple[int, int] | tuple[str, str]
|
||||
reveal_type(list_of_pairs) # revealed: list[tuple[str, str]]
|
||||
reveal_type(list_or_tuple_of_ints) # revealed: list[int] | tuple[int, ...]
|
||||
reveal_type(annotated_int) # revealed: int
|
||||
reveal_type(subclass_of_int) # revealed: type[int]
|
||||
# TODO: This should be `(int, /) -> str`
|
||||
reveal_type(callable_int_to_str) # revealed: Unknown
|
||||
```
|
||||
|
||||
A generic implicit type alias can also be used in another generic implicit type alias:
|
||||
|
||||
@@ -124,9 +124,11 @@ T = TypeVar("T")
|
||||
Alias1: TypeAlias = list[T] | set[T]
|
||||
MyAlias: TypeAlias = int | Alias1[str]
|
||||
|
||||
def _():
|
||||
reveal_type(Alias1) # revealed: types.UnionType
|
||||
|
||||
def _(x: MyAlias):
|
||||
# TODO: int | list[str] | set[str]
|
||||
reveal_type(x) # revealed: int | @Todo(Specialization of union type alias)
|
||||
reveal_type(x) # revealed: int | list[str] | set[str]
|
||||
```
|
||||
|
||||
## Imported
|
||||
|
||||
@@ -11113,8 +11113,13 @@ impl<'db, 'ast> TypeInferenceBuilder<'db, 'ast> {
|
||||
.map(Type::from)
|
||||
.unwrap_or_else(Type::unknown);
|
||||
}
|
||||
Type::KnownInstance(KnownInstanceType::UnionType(_)) => {
|
||||
return todo_type!("Specialization of union type alias");
|
||||
Type::KnownInstance(
|
||||
KnownInstanceType::UnionType(_)
|
||||
| KnownInstanceType::Annotated(_)
|
||||
| KnownInstanceType::Callable(_)
|
||||
| KnownInstanceType::TypeGenericAlias(_),
|
||||
) => {
|
||||
return self.infer_explicitly_specialized_type_alias(subscript, value_ty, false);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user