Skip to content

Commit dda6ff2

Browse files
committed
refactro
1 parent caf8d55 commit dda6ff2

1 file changed

Lines changed: 10 additions & 19 deletions

File tree

crates/codegen/src/symboltable.rs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1272,30 +1272,21 @@ impl SymbolTableBuilder {
12721272
current_scope,
12731273
Some(CompilerScope::Module | CompilerScope::Class)
12741274
);
1275+
let needs_non_future_conditional_annotations = is_ann_assign
1276+
&& !self.future_annotations
1277+
&& (matches!(current_scope, Some(CompilerScope::Module))
1278+
|| (matches!(current_scope, Some(CompilerScope::Class)) && self.in_conditional_block));
1279+
let should_register_conditional_annotations = needs_future_annotation_bookkeeping
1280+
|| (needs_non_future_conditional_annotations
1281+
&& !self.tables.last().unwrap().has_conditional_annotations);
12751282

12761283
// PEP 649: Only AnnAssign annotations can be conditional.
12771284
// Function parameter/return annotations are never conditional.
1278-
if is_ann_assign && !self.future_annotations {
1279-
let is_conditional = matches!(current_scope, Some(CompilerScope::Module))
1280-
|| (matches!(current_scope, Some(CompilerScope::Class))
1281-
&& self.in_conditional_block);
1282-
1283-
if is_conditional && !self.tables.last().unwrap().has_conditional_annotations {
1284-
self.tables.last_mut().unwrap().has_conditional_annotations = true;
1285-
self.register_name(
1286-
"__conditional_annotations__",
1287-
SymbolUsage::Assigned,
1288-
annotation.range(),
1289-
)?;
1290-
self.register_name(
1291-
"__conditional_annotations__",
1292-
SymbolUsage::Used,
1293-
annotation.range(),
1294-
)?;
1295-
}
1285+
if needs_non_future_conditional_annotations {
1286+
self.tables.last_mut().unwrap().has_conditional_annotations = true;
12961287
}
12971288

1298-
if needs_future_annotation_bookkeeping {
1289+
if should_register_conditional_annotations {
12991290
self.register_name(
13001291
"__conditional_annotations__",
13011292
SymbolUsage::Assigned,

0 commit comments

Comments
 (0)