From f5aeb3754f2b175946b3cffcb784ad3b0fb421ab Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Mon, 25 Feb 2008 12:47:30 -0800 Subject: [PATCH] error on local cimport (rather than traceback) --- Cython/Compiler/Nodes.py | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Cython/Compiler/Nodes.py b/Cython/Compiler/Nodes.py index 8204427c..ce0e0fb7 100644 --- a/Cython/Compiler/Nodes.py +++ b/Cython/Compiler/Nodes.py @@ -3296,6 +3296,9 @@ class CImportStatNode(StatNode): # as_name string or None Name specified in "as" clause, if any def analyse_declarations(self, env): + if not env.is_module_scope: + error(self.pos, "cimport only allowed at module level") + return module_scope = env.find_module(self.module_name, self.pos) if "." in self.module_name: names = self.module_name.split(".") @@ -3328,6 +3331,9 @@ class FromCImportStatNode(StatNode): # imported_names [(pos, name, as_name)] Names to be imported def analyse_declarations(self, env): + if not env.is_module_scope: + error(self.pos, "cimport only allowed at module level") + return module_scope = env.find_module(self.module_name, self.pos) env.add_imported_module(module_scope) for pos, name, as_name in self.imported_names: -- 2.26.2