Add variable annotation syntax. Simplify grammar for comprehensions. Add capital J suffix for complex numbers.

This commit is contained in:
Windel Bouwman 2019-08-07 15:31:24 +02:00
parent 7e9b3ddc1f
commit b22698a6f1
2 changed files with 25 additions and 0 deletions

View file

@ -553,6 +553,20 @@ impl Compiler {
self.compile_op(op, true);
self.compile_store(target)?;
}
AnnAssign {
target,
annotation,
value,
} => {
// Throw away annotation:
self.compile_expression(annotation)?;
self.emit(Instruction::Pop);
if let Some(value) = value {
self.compile_expression(value)?;
self.compile_store(target)?;
}
}
Delete { targets } => {
for target in targets {
self.compile_delete(target)?;

View file

@ -335,6 +335,17 @@ impl SymbolTableBuilder {
self.scan_expression(target)?;
self.scan_expression(value)?;
}
AnnAssign {
target,
annotation,
value,
} => {
self.scan_expression(target)?;
self.scan_expression(annotation)?;
if let Some(value) = value {
self.scan_expression(value)?;
}
}
With { items, body, .. } => {
for item in items {
self.scan_expression(&item.context_expr)?;