mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 18:28:24 +00:00
[semantic-syntax-tests] for for InvalidStarExpression
, DuplicateMatchKey
, and DuplicateMatchClassAttribute
(#17754)
Re: #17526 ## Summary Add integration tests for Python Semantic Syntax for `InvalidStarExpression`, `DuplicateMatchKey`, and `DuplicateMatchClassAttribute`. ## Note - Red knot integration tests for `DuplicateMatchKey` exist already in line 89-101. <!-- What's the purpose of the change? What does it do, and why? --> ## Test Plan This is a test. <!-- How was it tested? -->
This commit is contained in:
parent
965a4dd731
commit
101e1a5ddd
7 changed files with 136 additions and 0 deletions
|
@ -100,6 +100,26 @@ match 2:
|
|||
...
|
||||
```
|
||||
|
||||
## Duplicate `match` class attribute
|
||||
|
||||
Attribute names in class patterns must be unique:
|
||||
|
||||
```toml
|
||||
[environment]
|
||||
python-version = "3.10"
|
||||
```
|
||||
|
||||
```py
|
||||
class Point:
|
||||
pass
|
||||
|
||||
obj = Point()
|
||||
match obj:
|
||||
# error: [invalid-syntax] "attribute name `x` repeated in class pattern"
|
||||
case Point(x=1, x=2):
|
||||
pass
|
||||
```
|
||||
|
||||
## `return`, `yield`, `yield from`, and `await` outside function
|
||||
|
||||
```py
|
||||
|
@ -186,6 +206,28 @@ def f[X, Y, X]():
|
|||
pass
|
||||
```
|
||||
|
||||
## Invalid star expression
|
||||
|
||||
Star expressions can't be used in certain contexts:
|
||||
|
||||
```py
|
||||
def func():
|
||||
# error: [invalid-syntax] "Starred expression cannot be used here"
|
||||
return *[1, 2, 3]
|
||||
|
||||
def gen():
|
||||
# error: [invalid-syntax] "Starred expression cannot be used here"
|
||||
yield * [1, 2, 3]
|
||||
|
||||
# error: [invalid-syntax] "Starred expression cannot be used here"
|
||||
for *x in range(10):
|
||||
pass
|
||||
|
||||
# error: [invalid-syntax] "Starred expression cannot be used here"
|
||||
for x in *range(10):
|
||||
pass
|
||||
```
|
||||
|
||||
## `await` outside async function
|
||||
|
||||
This error includes `await`, `async for`, `async with`, and `async` comprehensions.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue