From: Stefan Behnel Date: Sat, 16 Apr 2011 05:56:15 +0000 (+0200) Subject: implement #686: turn 'undeclared builtin' error into a visible warning, look up unkno... X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=dfa643cf961e192990eaa51f776641b31772e7c7;p=cython.git implement #686: turn 'undeclared builtin' error into a visible warning, look up unknown builtins at runtime when (and if) they are needed --- diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index ef2911e6..c2baa8d1 100755 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -1339,7 +1339,7 @@ class NameNode(AtomicExprNode): if entry and entry.is_cfunction: var_entry = entry.as_variable if var_entry: - if var_entry.is_builtin and Options.cache_builtins: + if var_entry.is_builtin and var_entry.is_const: var_entry = env.declare_builtin(var_entry.name, self.pos) node = NameNode(self.pos, name = self.name) node.entry = var_entry @@ -1436,7 +1436,7 @@ class NameNode(AtomicExprNode): if entry.is_declared_generic: self.result_ctype = py_object_type if entry.is_pyglobal or entry.is_builtin: - if Options.cache_builtins and entry.is_builtin: + if entry.is_builtin and entry.is_const: self.is_temp = 0 else: self.is_temp = 1 @@ -1447,7 +1447,7 @@ class NameNode(AtomicExprNode): if self.is_used_as_rvalue: entry = self.entry if entry.is_builtin: - if not Options.cache_builtins: # cached builtins are ok + if not entry.is_const: # cached builtins are ok self.gil_error() elif entry.is_pyglobal: self.gil_error() @@ -1525,7 +1525,7 @@ class NameNode(AtomicExprNode): entry = self.entry if entry is None: return # There was an error earlier - if entry.is_builtin and Options.cache_builtins: + if entry.is_builtin and entry.is_const: return # Lookup already cached elif entry.is_pyclass_attr: assert entry.type.is_pyobject, "Python global or builtin not a Python object" diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index f86bb164..d52317bb 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -760,7 +760,7 @@ class BuiltinScope(Scope): if self.outer_scope is not None: return self.outer_scope.declare_builtin(name, pos) else: - error(pos, "undeclared name not builtin: %s"%name) + warning(pos, "undeclared name not builtin: %s" % name, 2) def declare_builtin_cfunction(self, name, type, cname, python_equiv = None, utility_code = None): @@ -916,10 +916,16 @@ class ModuleScope(Scope): if self.has_import_star: entry = self.declare_var(name, py_object_type, pos) return entry - elif self.outer_scope is not None: - return self.outer_scope.declare_builtin(name, pos) + ## elif self.outer_scope is not None: + ## entry = self.outer_scope.declare_builtin(name, pos) + ## print entry + ## return entry else: - error(pos, "undeclared name not builtin: %s"%name) + # unknown - assume it's builtin and look it up at runtime + warning(pos, "undeclared name not builtin: %s" % name, 2) + entry = self.declare(name, None, py_object_type, pos, 'private') + entry.is_builtin = 1 + return entry if Options.cache_builtins: for entry in self.cached_builtins: if entry.name == name: diff --git a/tests/run/builtinnames.pyx b/tests/run/builtinnames.pyx index 1d018a55..46539582 100644 --- a/tests/run/builtinnames.pyx +++ b/tests/run/builtinnames.pyx @@ -56,14 +56,3 @@ def test_for_in_range(arg): for c in range(arg): l.append(c) return l - -def raise_and_catch_BaseException(): - """ - >>> raise_and_catch_BaseException() - 1 - """ - try: - raise BaseException - except BaseException: - return 1 - return 2