mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-29 13:24:57 +00:00
Fix panic for illegal Literal[…]
annotations with inner subscript expressions (#19489)
## Summary Fixes pull-types panics for illegal annotations like `Literal[object[index]]`. Originally reported by @AlexWaygood ## Test Plan * Verified that this caused panics in the playground, when typing (and potentially hovering over) `x: Literal[obj[0]]`. * Added a regression test
This commit is contained in:
parent
fd335eb8b7
commit
ee69d38000
2 changed files with 5 additions and 0 deletions
|
@ -60,6 +60,10 @@ class NotAnEnum:
|
|||
|
||||
# error: [invalid-type-form]
|
||||
invalid5: Literal[NotAnEnum.x]
|
||||
|
||||
a_list: list[int] = [1, 2, 3]
|
||||
# error: [invalid-type-form]
|
||||
invalid6: Literal[a_list[0]]
|
||||
```
|
||||
|
||||
## Shortening unions of literals
|
||||
|
|
|
@ -10438,6 +10438,7 @@ impl<'db> TypeInferenceBuilder<'db, '_> {
|
|||
self.store_expression_type(parameters, ty);
|
||||
ty
|
||||
} else {
|
||||
self.infer_expression(slice);
|
||||
self.store_expression_type(parameters, Type::unknown());
|
||||
|
||||
return Err(vec![parameters]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue