Skip to content

Commit 0a44b07

Browse files
committed
Patch panics for stringified annotations for now
1 parent b4208f6 commit 0a44b07

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

crates/ty_python_semantic/resources/mdtest/implicit_type_aliases.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -558,6 +558,23 @@ def _(
558558
reveal_type(list_of_ints2) # revealed: list[int]
559559
```
560560

561+
### In stringified annotations
562+
563+
Generic implicit type aliases can be specialized in stringified annotations:
564+
565+
```py
566+
from typing_extensions import TypeVar
567+
568+
T = TypeVar("T")
569+
570+
MyList = list[T]
571+
572+
def _(
573+
list_of_ints: "MyList[int]",
574+
):
575+
reveal_type(list_of_ints) # revealed: @Todo(Specialization of generic type alias in stringified annotation)
576+
```
577+
561578
### Error cases
562579

563580
A generic alias that is already fully specialized cannot be specialized again:

crates/ty_python_semantic/src/types/infer/builder/type_expression.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -723,6 +723,14 @@ impl<'db> TypeInferenceBuilder<'db, '_> {
723723
) -> Type<'db> {
724724
let db = self.db();
725725

726+
if self
727+
.index
728+
.try_expression_scope_id(&ast::ExprRef::from(subscript))
729+
.is_none()
730+
{
731+
return todo_type!("Specialization of generic type alias in stringified annotation");
732+
}
733+
726734
let definitions = match &*subscript.value {
727735
ast::Expr::Name(id) => {
728736
// TODO: This is an expensive call to an API that was never meant to be called from

0 commit comments

Comments
 (0)