Skip to content

Commit ff273ba

Browse files
committed
update test visitor, remove unused in_generator_scope
1 parent 7ee846b commit ff273ba

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

crates/ruff_linter/src/checkers/ast/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -655,10 +655,6 @@ impl SemanticSyntaxContext for Checker<'_> {
655655
kind.is_function() || kind.is_lambda()
656656
}
657657

658-
fn in_generator_scope(&self) -> bool {
659-
self.semantic.current_scope().kind.is_generator()
660-
}
661-
662658
fn in_notebook(&self) -> bool {
663659
self.source_type.is_ipynb()
664660
}

crates/ruff_python_parser/src/semantic_errors.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1523,9 +1523,6 @@ pub trait SemanticSyntaxContext {
15231523
/// Returns `true` if the visitor is in a function scope.
15241524
fn in_function_scope(&self) -> bool;
15251525

1526-
/// Returns `true` if the visitor is in a generator scope.
1527-
fn in_generator_scope(&self) -> bool;
1528-
15291526
/// Returns `true` if the source file is a Jupyter notebook.
15301527
fn in_notebook(&self) -> bool;
15311528

crates/ruff_python_parser/tests/fixtures.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -464,6 +464,7 @@ enum Scope {
464464
Module,
465465
Function { is_async: bool },
466466
Comprehension { is_async: bool },
467+
Class,
467468
}
468469

469470
impl Scope {
@@ -575,12 +576,28 @@ impl SemanticSyntaxContext for SemanticSyntaxCheckerVisitor<'_> {
575576
fn in_notebook(&self) -> bool {
576577
false
577578
}
579+
580+
fn in_function_context(&self) -> bool {
581+
for scope in self.scopes() {
582+
match scope {
583+
Scope::Class => return false,
584+
Scope::Function { .. } => return true,
585+
Scope::Comprehension { .. } | Scope::Module => {}
586+
}
587+
}
588+
false
589+
}
578590
}
579591

580592
impl Visitor<'_> for SemanticSyntaxCheckerVisitor<'_> {
581593
fn visit_stmt(&mut self, stmt: &ast::Stmt) {
582594
self.with_semantic_checker(|semantic, context| semantic.visit_stmt(stmt, context));
583595
match stmt {
596+
ast::Stmt::ClassDef(_) => {
597+
self.scopes.push(Scope::Class);
598+
ast::visitor::walk_stmt(self, stmt);
599+
self.scopes.pop().unwrap();
600+
}
584601
ast::Stmt::FunctionDef(ast::StmtFunctionDef { is_async, .. }) => {
585602
self.scopes.push(Scope::Function {
586603
is_async: *is_async,

0 commit comments

Comments
 (0)