From 11af619455285c41188b09071abced3dfb8398c9 Mon Sep 17 00:00:00 2001 From: z78078 Date: Fri, 8 Jul 2022 17:26:40 +0800 Subject: [PATCH] nac3artiq: add class name to the error message when rpc decorator found in __init__ function --- nac3artiq/src/lib.rs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/nac3artiq/src/lib.rs b/nac3artiq/src/lib.rs index d9498825..c0eac074 100644 --- a/nac3artiq/src/lib.rs +++ b/nac3artiq/src/lib.rs @@ -390,7 +390,8 @@ impl Nac3 { } } StmtKind::ClassDef { name, body, .. } => { - let class_obj = module.getattr(py, name.to_string()).unwrap(); + let class_name = name.to_string(); + let class_obj = module.getattr(py, &class_name).unwrap(); for stmt in body.iter() { if let StmtKind::FunctionDef { name, decorator_list, .. } = &stmt.node { if let Some(location) = decorator_list @@ -405,8 +406,8 @@ impl Nac3 { // This part check if __init__ method decorate with inappropriate decorator (rpc) if name == &"__init__".into() { return Err(CompileError::new_err(format!( - "compilation failed\n----------\nConstructor __init__ function should not decorated with rpc decorator (at {})", - location + "compilation failed\n----------\nClass {} Constructor __init__ function should not decorated with rpc decorator (at {})", + class_name, location ))); } rpc_ids.push((Some((class_obj.clone(), *name)), def_id));