Skip to content

Commit faeed2c

Browse files
committed
clean up
1 parent 133bdf6 commit faeed2c

File tree

3 files changed

+36
-44
lines changed

3 files changed

+36
-44
lines changed

crates/codegen/src/compile.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,12 +1191,7 @@ impl Compiler {
11911191

11921192
// Jump to body if format <= 2 (comparison is false)
11931193
let body_block = self.new_block();
1194-
emit!(
1195-
self,
1196-
Instruction::PopJumpIfFalse {
1197-
target: body_block,
1198-
}
1199-
);
1194+
emit!(self, Instruction::PopJumpIfFalse { target: body_block });
12001195

12011196
// Raise NotImplementedError
12021197
let not_implemented_error = self.name("NotImplementedError");

crates/vm/src/builtins/function.rs

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -605,12 +605,10 @@ impl PyFunction {
605605
// Check for callable __annotate__ and clone it before calling
606606
let annotate_fn = {
607607
let annotate = self.annotate.lock();
608-
if let Some(ref func) = *annotate {
609-
if func.is_callable() {
610-
Some(func.clone())
611-
} else {
612-
None
613-
}
608+
if let Some(ref func) = *annotate
609+
&& func.is_callable()
610+
{
611+
Some(func.clone())
614612
} else {
615613
None
616614
}
@@ -641,26 +639,24 @@ impl PyFunction {
641639
}
642640

643641
#[pygetset(setter)]
644-
fn set___annotations__(&self, value: PySetterValue, vm: &VirtualMachine) -> PyResult<()> {
645-
match value {
646-
PySetterValue::Assign(value) => {
647-
if vm.is_none(&value) {
648-
*self.annotations.lock() = None;
649-
} else {
650-
let annotations =
651-
value.downcast::<crate::builtins::PyDict>().map_err(|_| {
652-
vm.new_type_error("__annotations__ must be set to a dict object")
653-
})?;
654-
*self.annotations.lock() = Some(annotations);
655-
}
656-
// Clear __annotate__ when __annotations__ is set
657-
*self.annotate.lock() = None;
658-
}
659-
PySetterValue::Delete => {
660-
*self.annotations.lock() = None;
661-
*self.annotate.lock() = None;
642+
fn set___annotations__(
643+
&self,
644+
value: PySetterValue<Option<PyObjectRef>>,
645+
vm: &VirtualMachine,
646+
) -> PyResult<()> {
647+
let annotations = match value {
648+
PySetterValue::Assign(Some(value)) => {
649+
let annotations = value.downcast::<crate::builtins::PyDict>().map_err(|_| {
650+
vm.new_type_error("__annotations__ must be set to a dict object")
651+
})?;
652+
Some(annotations)
662653
}
663-
}
654+
PySetterValue::Assign(None) | PySetterValue::Delete => None,
655+
};
656+
*self.annotations.lock() = annotations;
657+
658+
// Clear __annotate__ when __annotations__ is set
659+
*self.annotate.lock() = None;
664660
Ok(())
665661
}
666662

@@ -673,23 +669,26 @@ impl PyFunction {
673669
}
674670

675671
#[pygetset(setter)]
676-
fn set___annotate__(&self, value: PySetterValue, vm: &VirtualMachine) -> PyResult<()> {
677-
match value {
678-
PySetterValue::Assign(value) => {
679-
if vm.is_none(&value) {
680-
*self.annotate.lock() = Some(value);
681-
} else if value.is_callable() {
682-
*self.annotate.lock() = Some(value);
683-
// Clear cached __annotations__ when __annotate__ is set
684-
*self.annotations.lock() = None;
685-
} else {
672+
fn set___annotate__(
673+
&self,
674+
value: PySetterValue<Option<PyObjectRef>>,
675+
vm: &VirtualMachine,
676+
) -> PyResult<()> {
677+
let annotate = match value {
678+
PySetterValue::Assign(Some(value)) => {
679+
if !value.is_callable() {
686680
return Err(vm.new_type_error("__annotate__ must be callable or None"));
687681
}
682+
// Clear cached __annotations__ when __annotate__ is set
683+
*self.annotations.lock() = None;
684+
Some(value)
688685
}
686+
PySetterValue::Assign(None) => None,
689687
PySetterValue::Delete => {
690688
return Err(vm.new_type_error("__annotate__ cannot be deleted"));
691689
}
692-
}
690+
};
691+
*self.annotate.lock() = annotate;
693692
Ok(())
694693
}
695694

crates/vm/src/vm/vm_new.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,6 @@ impl VirtualMachine {
6565
pub fn new_scope_with_main(&self) -> PyResult<Scope> {
6666
let scope = self.new_scope_with_builtins();
6767
let main_module = self.new_module("__main__", scope.globals.clone(), None);
68-
// PEP 649: Don't automatically initialize __annotations__
69-
// It will be lazily created by the descriptor when accessed
7068

7169
self.sys_module.get_attr("modules", self)?.set_item(
7270
"__main__",

0 commit comments

Comments
 (0)