mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-30 13:51:37 +00:00
[red-knot] Do not panic when encountering string annotations (#14091)
## Summary Encountered this while running red-knot benchmarks on the `black` codebase. Fixes two of the issues in #13478. ## Test Plan Added a regression test.
This commit is contained in:
parent
df45a0e3f9
commit
6dabf045c3
2 changed files with 13 additions and 1 deletions
|
@ -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
|
||||||
|
```
|
|
@ -3725,7 +3725,10 @@ impl<'db> TypeInferenceBuilder<'db> {
|
||||||
// TODO: parse the expression and check whether it is a string annotation, since they
|
// TODO: parse the expression and check whether it is a string annotation, since they
|
||||||
// can be annotation expressions distinct from type expressions.
|
// can be annotation expressions distinct from type expressions.
|
||||||
// https://typing.readthedocs.io/en/latest/spec/annotations.html#string-annotations
|
// https://typing.readthedocs.io/en/latest/spec/annotations.html#string-annotations
|
||||||
ast::Expr::StringLiteral(_literal) => Type::Todo,
|
ast::Expr::StringLiteral(_literal) => {
|
||||||
|
self.store_expression_type(expression, Type::Todo);
|
||||||
|
Type::Todo
|
||||||
|
}
|
||||||
|
|
||||||
// Annotation expressions also get special handling for `*args` and `**kwargs`.
|
// Annotation expressions also get special handling for `*args` and `**kwargs`.
|
||||||
ast::Expr::Starred(starred) => self.infer_starred_expression(starred),
|
ast::Expr::Starred(starred) => self.infer_starred_expression(starred),
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue