8
8
#![ deny( clippy:: cast_possible_truncation) ]
9
9
10
10
use crate :: {
11
- IndexSet , ToPythonName ,
11
+ IndexMap , IndexSet , ToPythonName ,
12
12
error:: { CodegenError , CodegenErrorType , PatternUnreachableReason } ,
13
13
ir:: { self , BlockIdx } ,
14
- symboltable:: { self , SymbolFlags , SymbolScope , SymbolTable } ,
14
+ symboltable:: { self , SymbolFlags , SymbolScope , SymbolTable , SymbolTableType } ,
15
15
unparse:: unparse_expr,
16
16
} ;
17
17
use itertools:: Itertools ;
@@ -318,6 +318,8 @@ impl<'src> Compiler<'src> {
318
318
varname_cache : IndexSet :: default ( ) ,
319
319
cellvar_cache : IndexSet :: default ( ) ,
320
320
freevar_cache : IndexSet :: default ( ) ,
321
+ fasthidden_cache : IndexMap :: default ( ) ,
322
+ static_attributes : None ,
321
323
} ;
322
324
Compiler {
323
325
code_stack : vec ! [ module_code] ,
@@ -382,6 +384,9 @@ impl Compiler<'_> {
382
384
let source_path = self . source_code . path . to_owned ( ) ;
383
385
let first_line_number = self . get_source_line_number ( ) ;
384
386
387
+ // Get the private name from current scope if exists
388
+ let private = self . code_stack . last ( ) . and_then ( |info| info. private . clone ( ) ) ;
389
+
385
390
let table = self . push_symbol_table ( ) ;
386
391
387
392
let cellvar_cache = table
@@ -400,17 +405,13 @@ impl Compiler<'_> {
400
405
. collect ( ) ;
401
406
402
407
// Initialize varname_cache from SymbolTable::varnames
403
- let varname_cache: IndexSet < String > = table
404
- . varnames
405
- . iter ( )
406
- . cloned ( )
407
- . collect ( ) ;
408
+ let varname_cache: IndexSet < String > = table. varnames . iter ( ) . cloned ( ) . collect ( ) ;
408
409
409
410
// Qualname will be set later by set_qualname
410
411
let qualname = None ;
411
412
412
- // Get the private name from current scope if exists
413
- let private = self . code_stack . last ( ) . and_then ( |info| info . private . clone ( ) ) ;
413
+ // Check if this is a class scope
414
+ let is_class_scope = table . typ == SymbolTableType :: Class ;
414
415
415
416
let info = ir:: CodeInfo {
416
417
flags,
@@ -430,6 +431,12 @@ impl Compiler<'_> {
430
431
varname_cache,
431
432
cellvar_cache,
432
433
freevar_cache,
434
+ fasthidden_cache : IndexMap :: default ( ) ,
435
+ static_attributes : if is_class_scope {
436
+ Some ( IndexSet :: default ( ) )
437
+ } else {
438
+ None
439
+ } ,
433
440
} ;
434
441
self . code_stack . push ( info) ;
435
442
}
0 commit comments