mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-04 02:38:25 +00:00
[ty] Don't warn yield
not in function when yield
is in function (#18008)
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run
Some checks are pending
CI / Determine changes (push) Waiting to run
CI / cargo fmt (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run
This commit is contained in:
parent
d37592175f
commit
02fd48132c
7 changed files with 87 additions and 17 deletions
|
@ -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
|
||||
|
|
|
@ -2481,6 +2481,18 @@ impl SemanticSyntaxContext for SemanticIndexBuilder<'_> {
|
|||
false
|
||||
}
|
||||
|
||||
fn in_yield_allowed_context(&self) -> bool {
|
||||
for scope_info in self.scope_stack.iter().rev() {
|
||||
let scope = &self.scopes[scope_info.file_scope_id];
|
||||
match scope.kind() {
|
||||
ScopeKind::Class | ScopeKind::Comprehension => return false,
|
||||
ScopeKind::Function | ScopeKind::Lambda => return true,
|
||||
ScopeKind::Module | ScopeKind::TypeAlias | ScopeKind::Annotation => {}
|
||||
}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
fn in_sync_comprehension(&self) -> bool {
|
||||
for scope_info in self.scope_stack.iter().rev() {
|
||||
let scope = &self.scopes[scope_info.file_scope_id];
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue