mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:39:12 +00:00
[syntax-errors] Fix star annotation before Python 3.11 (#16878)
Summary -- Fixes #16874. I previously emitted a syntax error when starred annotations were _allowed_ rather than when they were actually used. This caused false positives for any starred parameter name because these are allowed to have starred annotations but not required to. The fix is to check if the annotation is actually starred after parsing it. Test Plan -- New inline parser tests derived from the initial report and more examples from the comments, although I think the first case should cover them all.
This commit is contained in:
parent
67602512b6
commit
42cbce538b
3 changed files with 415 additions and 4 deletions
|
@ -0,0 +1,9 @@
|
|||
# parse_options: {"target-version": "3.10"}
|
||||
# regression tests for https://github.com/astral-sh/ruff/issues/16874
|
||||
# starred parameters are fine, just not the annotation
|
||||
from typing import Annotated, Literal
|
||||
def foo(*args: Ts): ...
|
||||
def foo(*x: Literal["this should allow arbitrary strings"]): ...
|
||||
def foo(*x: Annotated[str, "this should allow arbitrary strings"]): ...
|
||||
def foo(*args: str, **kwds: int): ...
|
||||
def union(*x: A | B): ...
|
Loading…
Add table
Add a link
Reference in a new issue