Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[red-knot] Panics on (some) starred expressions in annotations #14115

Closed
sharkdp opened this issue Nov 5, 2024 · 0 comments · Fixed by #14106
Closed

[red-knot] Panics on (some) starred expressions in annotations #14115

sharkdp opened this issue Nov 5, 2024 · 0 comments · Fixed by #14106
Assignees
Labels
bug Something isn't working red-knot Multi-file analysis & type inference

Comments

@sharkdp
Copy link
Contributor

sharkdp commented Nov 5, 2024

Red knot currently panics on some instances of starred expressions (at the outermost layer) of type annotations. An actual example where something like this would occur is in variadic generics (the *Ts):

Ts = TypeVarTuple("Ts")

def append_int(*args: *Ts) -> tuple[*Ts, int]: …

In this particular case, we currently do not panic since we never run deferred inference on that parameter type. But we would panic if we were to implement function parameter inference.

A case which does lead to a panic is the following (invalid syntax) example:

def f() -> *int: ...
f()

(it's important that this occurs as a return type and that the function is actually called; it doesn't work otherwise)

A fix for this is already ready at #14106

@sharkdp sharkdp added bug Something isn't working red-knot Multi-file analysis & type inference labels Nov 5, 2024
@sharkdp sharkdp self-assigned this Nov 5, 2024
sharkdp added a commit that referenced this issue Nov 5, 2024
## Summary

- Store the expression type for annotations that are starred expressions
(see [discussion
here](#14091 (comment)))
- Use `self.store_expression_type(…)` consistently throughout, as it
makes sure that no double-insertion errors occur.

closes #14115

## Test Plan

Added an invalid-syntax example to the corpus which leads to a panic on
`main`. Also added a Markdown test with a valid-syntax example that
would lead to a panic once we implement function parameter inference.

---------

Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working red-knot Multi-file analysis & type inference
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant