[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:
Max Mynter 2025-05-05 19:30:16 +02:00 committed by GitHub
parent 965a4dd731
commit 101e1a5ddd
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 136 additions and 0 deletions

View file

@ -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.