Skip to content

Commit

Permalink
[red-knot] Do not panic when encountering string annotations
Browse files Browse the repository at this point in the history
  • Loading branch information
sharkdp committed Nov 4, 2024
1 parent e302c2d commit 5fb8ca7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# String annotations

```py
def f() -> "int":
return 1

# TODO: We do not support string annotations, but we should not panic if we encounter them
reveal_type(f()) # revealed: @Todo
```
7 changes: 6 additions & 1 deletion crates/red_knot_python_semantic/src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,12 @@ fn definition_expression_ty<'db>(
if let Some(ty) = inference.try_expression_ty(expr_id) {
ty
} else {
infer_deferred_types(db, definition).expression_ty(expr_id)
infer_deferred_types(db, definition)
.try_expression_ty(expr_id)
.unwrap_or(
// Some deferred cases like string annotations are not yet implemented
Type::Todo,
)
}
}

Expand Down

0 comments on commit 5fb8ca7

Please sign in to comment.