From 0b25d4b9752ebd18aafd73daeff100757a549cd5 Mon Sep 17 00:00:00 2001 From: Vitja Makarov Date: Wed, 9 Mar 2011 09:01:14 +0300 Subject: [PATCH] Handle sequence in DelStatNode, see #668 --- Cython/Compiler/Nodes.py | 19 +++++++++++++++---- Cython/Compiler/TypeInference.py | 2 +- tests/run/delete.pyx | 9 +++++++++ 3 files changed, 25 insertions(+), 5 deletions(-) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 609489f1..f84bc8c8 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -3785,12 +3785,23 @@ class DelStatNode(StatNode): child_attrs = ["args"] + def flatten_args(self): + return self._flatten_args(self, []) + + def _flatten_args(self, seq, result): + for arg in seq.args: + if arg.is_sequence_constructor: + self._flatten_args(arg, result) + else: + result.append(arg) + return result + def analyse_declarations(self, env): - for arg in self.args: + for arg in self.flatten_args(): arg.analyse_target_declaration(env) def analyse_expressions(self, env): - for arg in self.args: + for arg in self.flatten_args(): arg.analyse_target_expression(env, None) if arg.type.is_pyobject: pass @@ -3803,14 +3814,14 @@ class DelStatNode(StatNode): #arg.release_target_temp(env) def nogil_check(self, env): - for arg in self.args: + for arg in self.flatten_args(): if arg.type.is_pyobject: self.gil_error() gil_message = "Deleting Python object" def generate_execution_code(self, code): - for arg in self.args: + for arg in self.flatten_args(): if arg.type.is_pyobject: arg.generate_deletion_code(code) elif arg.type.is_ptr and arg.type.base_type.is_cpp_class: diff --git a/Cython/Compiler/TypeInference.py b/Cython/Compiler/TypeInference.py index c788d02c..87fcb869 100644 --- a/Cython/Compiler/TypeInference.py +++ b/Cython/Compiler/TypeInference.py @@ -122,7 +122,7 @@ class MarkAssignments(CythonTransform): return node def visit_DelStatNode(self, node): - for arg in node.args: + for arg in node.flatten_args(): self.mark_assignment(arg, arg) self.visitchildren(node) return node diff --git a/tests/run/delete.pyx b/tests/run/delete.pyx index 7157078a..efe121c7 100644 --- a/tests/run/delete.pyx +++ b/tests/run/delete.pyx @@ -87,3 +87,12 @@ def del_local(a): """ del a assert a is None # Until we have unbound locals... + +def del_seq(a, b, c): + """ + >>> del_seq(1, 2, 3) + """ + del a, (b, c) + assert a is None # Until we have unbound locals... + assert b is None # Until we have unbound locals... + assert c is None # Until we have unbound locals... -- 2.26.2