# HG changeset patch # User Emmanuel Gil Peyrot # Date 1465777128 -3600 # Node ID 53817b39f13952dbfe972f5c5a83a23643b39627 # Parent 5df52b40fe54c76c0b295df18f80d874f486131e Add FunctionDef.decorator_list support. diff --git a/src/ast_convert.rs b/src/ast_convert.rs --- a/src/ast_convert.rs +++ b/src/ast_convert.rs @@ -564,16 +564,16 @@ fn parse_statement(py: Python, ast: PyOb let name = ast.getattr(py, "name").unwrap(); let args = ast.getattr(py, "args").unwrap(); let body = ast.getattr(py, "body").unwrap(); + let decorator_list = ast.getattr(py, "decorator_list").unwrap(); let returns = ast.getattr(py, "returns").unwrap(); let name = get_str(py, name); let args = parse_arguments(py, args); let body = parse_list(py, body, parse_statement); - - let decorators = vec!(); + let decorator_list = parse_list(py, decorator_list, parse_expr); let returns = parse_optional_expr(py, returns); - stmt::FunctionDef(name, args, body, decorators, returns) + stmt::FunctionDef(name, args, body, decorator_list, returns) } else if is_instance(&ast, &global_type) { let names = ast.getattr(py, "names").unwrap(); let names = parse_list(py, names, get_str); diff --git a/src/ast_dump.rs b/src/ast_dump.rs --- a/src/ast_dump.rs +++ b/src/ast_dump.rs @@ -227,7 +227,15 @@ impl stmt { match self.clone() { stmt::ClassDef(name, bases, keywords, body, decorator_list) => format!("{}class {}({}):\n{}", current_indent, name, vec_to_strings_vec(bases).join(", "), statements_to_string(indent, body)), stmt::FunctionDef(name, arguments, body, decorator_list, returns) => { - format!("{}def {}({}){}:\n{}", + format!("{}{}def {}({}){}:\n{}", + { + let decorators = vec_to_strings_vec(decorator_list); + if decorators.is_empty() { + String::new() + } else { + format!("{}@{}\n", current_indent, decorators.join(format!("\n{}@", current_indent).as_str())) + } + }, current_indent, name, arguments.to_string(), diff --git a/tests/test_parse_files/test_functiondef_decorators.py b/tests/test_parse_files/test_functiondef_decorators.py new file mode 100644 --- /dev/null +++ b/tests/test_parse_files/test_functiondef_decorators.py @@ -0,0 +1,7 @@ +import cython +@cython.locals(a=int) +@cython.returns(int) +@cython.cfunc +def id(a): + return a +print(id(5))