@@ -240,21 +240,21 @@ fn analyze_symbol_table(symbol_table: &mut SymbolTable) -> SymbolTableResult {
240
240
*/
241
241
fn drop_class_free ( symbol_table : & mut SymbolTable ) {
242
242
// Check if __class__ is used as a free variable
243
- if let Some ( class_symbol) = symbol_table. symbols . get ( "__class__" ) {
244
- if class_symbol. scope == SymbolScope :: Free {
245
- symbol_table . needs_class_closure = true ;
246
- // Note: In CPython, the symbol is removed from the free set,
247
- // but in RustPython we handle this differently during code generation
248
- }
243
+ if let Some ( class_symbol) = symbol_table. symbols . get ( "__class__" )
244
+ && class_symbol. scope == SymbolScope :: Free
245
+ {
246
+ symbol_table . needs_class_closure = true ;
247
+ // Note: In CPython, the symbol is removed from the free set,
248
+ // but in RustPython we handle this differently during code generation
249
249
}
250
250
251
251
// Check if __classdict__ is used as a free variable
252
- if let Some ( classdict_symbol) = symbol_table. symbols . get ( "__classdict__" ) {
253
- if classdict_symbol. scope == SymbolScope :: Free {
254
- symbol_table . needs_classdict = true ;
255
- // Note: In CPython, the symbol is removed from the free set,
256
- // but in RustPython we handle this differently during code generation
257
- }
252
+ if let Some ( classdict_symbol) = symbol_table. symbols . get ( "__classdict__" )
253
+ && classdict_symbol. scope == SymbolScope :: Free
254
+ {
255
+ symbol_table . needs_classdict = true ;
256
+ // Note: In CPython, the symbol is removed from the free set,
257
+ // but in RustPython we handle this differently during code generation
258
258
}
259
259
}
260
260
@@ -733,12 +733,12 @@ impl SymbolTableBuilder {
733
733
734
734
fn scan_statement ( & mut self , statement : & Stmt ) -> SymbolTableResult {
735
735
use ruff_python_ast:: * ;
736
- if let Stmt :: ImportFrom ( StmtImportFrom { module, names, .. } ) = & statement {
737
- if module. as_ref ( ) . map ( |id| id. as_str ( ) ) == Some ( "__future__" ) {
738
- for feature in names {
739
- if & feature. name == "annotations" {
740
- self . future_annotations = true ;
741
- }
736
+ if let Stmt :: ImportFrom ( StmtImportFrom { module, names, .. } ) = & statement
737
+ && module. as_ref ( ) . map ( |id| id. as_str ( ) ) == Some ( "__future__" )
738
+ {
739
+ for feature in names {
740
+ if & feature . name == "annotations" {
741
+ self . future_annotations = true ;
742
742
}
743
743
}
744
744
}
@@ -1032,26 +1032,23 @@ impl SymbolTableBuilder {
1032
1032
use ruff_python_ast:: * ;
1033
1033
1034
1034
// Check for expressions not allowed in type parameters scope
1035
- if let Some ( table) = self . tables . last ( ) {
1036
- if table. typ == CompilerScope :: TypeParams {
1037
- if let Some ( keyword) = match expression {
1038
- Expr :: Yield ( _) | Expr :: YieldFrom ( _) => Some ( "yield" ) ,
1039
- Expr :: Await ( _) => Some ( "await" ) ,
1040
- Expr :: Named ( _) => Some ( "named" ) ,
1041
- _ => None ,
1042
- } {
1043
- return Err ( SymbolTableError {
1044
- error : format ! (
1045
- "{keyword} expression cannot be used within a type parameter"
1046
- ) ,
1047
- location : Some (
1048
- self . source_file
1049
- . to_source_code ( )
1050
- . source_location ( expression. range ( ) . start ( ) ) ,
1051
- ) ,
1052
- } ) ;
1053
- }
1035
+ if let Some ( table) = self . tables . last ( )
1036
+ && table. typ == CompilerScope :: TypeParams
1037
+ && let Some ( keyword) = match expression {
1038
+ Expr :: Yield ( _) | Expr :: YieldFrom ( _) => Some ( "yield" ) ,
1039
+ Expr :: Await ( _) => Some ( "await" ) ,
1040
+ Expr :: Named ( _) => Some ( "named" ) ,
1041
+ _ => None ,
1054
1042
}
1043
+ {
1044
+ return Err ( SymbolTableError {
1045
+ error : format ! ( "{keyword} expression cannot be used within a type parameter" ) ,
1046
+ location : Some (
1047
+ self . source_file
1048
+ . to_source_code ( )
1049
+ . source_location ( expression. range ( ) . start ( ) ) ,
1050
+ ) ,
1051
+ } ) ;
1055
1052
}
1056
1053
1057
1054
match expression {
0 commit comments