[ty] Don't warn yield not in function when yield is in function (#18008)

This commit is contained in:
Max Mynter 2025-05-21 18:16:25 +02:00 committed by GitHub
parent d37592175f
commit 02fd48132c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 87 additions and 17 deletions

View file

@ -298,25 +298,25 @@ python-version = "3.12"
```
```py
# error: [invalid-type-form] "`yield` expressions are not allowed in type expressions"
# error: [invalid-syntax] "yield expression cannot be used within a TypeVar bound"
# error: [invalid-syntax] "`yield` statement outside of a function"
type X[T: (yield 1)] = int
def _():
# error: [invalid-type-form] "`yield` expressions are not allowed in type expressions"
# error: [invalid-syntax] "yield expression cannot be used within a TypeVar bound"
type X[T: (yield 1)] = int
# error: [invalid-type-form] "`yield` expressions are not allowed in type expressions"
# error: [invalid-syntax] "yield expression cannot be used within a type alias"
# error: [invalid-syntax] "`yield` statement outside of a function"
type Y = (yield 1)
def _():
# error: [invalid-type-form] "`yield` expressions are not allowed in type expressions"
# error: [invalid-syntax] "yield expression cannot be used within a type alias"
type Y = (yield 1)
# error: [invalid-type-form] "Named expressions are not allowed in type expressions"
# error: [invalid-syntax] "named expression cannot be used within a generic definition"
def f[T](x: int) -> (y := 3):
return x
# error: [invalid-syntax] "`yield from` statement outside of a function"
# error: [invalid-syntax] "yield expression cannot be used within a generic definition"
class C[T]((yield from [object])):
pass
def _():
# error: [invalid-syntax] "yield expression cannot be used within a generic definition"
class C[T]((yield from [object])):
pass
```
## `await` outside async function