File tree Expand file tree Collapse file tree 3 files changed +17
-7
lines changed
ruff_linter/src/checkers/ast Expand file tree Collapse file tree 3 files changed +17
-7
lines changed Original file line number Diff line number Diff line change @@ -655,10 +655,6 @@ impl SemanticSyntaxContext for Checker<'_> {
655
655
kind. is_function ( ) || kind. is_lambda ( )
656
656
}
657
657
658
- fn in_generator_scope ( & self ) -> bool {
659
- self . semantic . current_scope ( ) . kind . is_generator ( )
660
- }
661
-
662
658
fn in_notebook ( & self ) -> bool {
663
659
self . source_type . is_ipynb ( )
664
660
}
Original file line number Diff line number Diff line change @@ -1523,9 +1523,6 @@ pub trait SemanticSyntaxContext {
1523
1523
/// Returns `true` if the visitor is in a function scope.
1524
1524
fn in_function_scope ( & self ) -> bool ;
1525
1525
1526
- /// Returns `true` if the visitor is in a generator scope.
1527
- fn in_generator_scope ( & self ) -> bool ;
1528
-
1529
1526
/// Returns `true` if the source file is a Jupyter notebook.
1530
1527
fn in_notebook ( & self ) -> bool ;
1531
1528
Original file line number Diff line number Diff line change @@ -464,6 +464,7 @@ enum Scope {
464
464
Module ,
465
465
Function { is_async : bool } ,
466
466
Comprehension { is_async : bool } ,
467
+ Class ,
467
468
}
468
469
469
470
impl Scope {
@@ -575,12 +576,28 @@ impl SemanticSyntaxContext for SemanticSyntaxCheckerVisitor<'_> {
575
576
fn in_notebook ( & self ) -> bool {
576
577
false
577
578
}
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
+ }
578
590
}
579
591
580
592
impl Visitor < ' _ > for SemanticSyntaxCheckerVisitor < ' _ > {
581
593
fn visit_stmt ( & mut self , stmt : & ast:: Stmt ) {
582
594
self . with_semantic_checker ( |semantic, context| semantic. visit_stmt ( stmt, context) ) ;
583
595
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
+ }
584
601
ast:: Stmt :: FunctionDef ( ast:: StmtFunctionDef { is_async, .. } ) => {
585
602
self . scopes . push ( Scope :: Function {
586
603
is_async : * is_async,
You can’t perform that action at this time.
0 commit comments