Enter annotation scope (PEP 649) Creates or reuses the annotation block for the current scope
(&mut self, line_number: u32)
| 1091 | /// Enter annotation scope (PEP 649) |
| 1092 | /// Creates or reuses the annotation block for the current scope |
| 1093 | fn enter_annotation_scope(&mut self, line_number: u32) { |
| 1094 | let current = self.tables.last_mut().unwrap(); |
| 1095 | let can_see_class_scope = |
| 1096 | current.typ == CompilerScope::Class || current.can_see_class_scope; |
| 1097 | let has_conditional = current.has_conditional_annotations; |
| 1098 | |
| 1099 | // Create annotation block if not exists |
| 1100 | if current.annotation_block.is_none() { |
| 1101 | let mut annotation_table = SymbolTable::new( |
| 1102 | "__annotate__".to_owned(), |
| 1103 | CompilerScope::Annotation, |
| 1104 | line_number, |
| 1105 | true, // is_nested |
| 1106 | ); |
| 1107 | // Annotation scope in class can see class scope |
| 1108 | annotation_table.can_see_class_scope = can_see_class_scope; |
| 1109 | // Add 'format' parameter |
| 1110 | annotation_table.varnames.push("format".to_owned()); |
| 1111 | current.annotation_block = Some(Box::new(annotation_table)); |
| 1112 | } |
| 1113 | |
| 1114 | // Take the annotation block and push to stack for processing |
| 1115 | let annotation_table = current.annotation_block.take().unwrap(); |
| 1116 | self.tables.push(*annotation_table); |
| 1117 | // Save parent's varnames and seed with existing annotation varnames (e.g., "format") |
| 1118 | self.varnames_stack |
| 1119 | .push(core::mem::take(&mut self.current_varnames)); |
| 1120 | self.current_varnames = self.tables.last().unwrap().varnames.clone(); |
| 1121 | |
| 1122 | if can_see_class_scope && !self.future_annotations { |
| 1123 | self.add_classdict_freevar(); |
| 1124 | // Also add __conditional_annotations__ as free var if parent has conditional annotations |
| 1125 | if has_conditional { |
| 1126 | self.add_conditional_annotations_freevar(); |
| 1127 | } |
| 1128 | } |
| 1129 | } |
| 1130 | |
| 1131 | /// Leave annotation scope (PEP 649) |
| 1132 | /// Stores the annotation block back to parent instead of sub_tables |
no test coverage detected