From c28ca95079e156765f44b3483870a40e58c714c0 Mon Sep 17 00:00:00 2001 From: Robert Bradshaw Date: Wed, 18 Mar 2009 22:48:13 -0700 Subject: [PATCH] Ticket #241, better error for keywords in cdef functions. --- Cython/Compiler/ExprNodes.py | 6 +++++- tests/errors/e_cdef_keywords_T241.pyx | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 tests/errors/e_cdef_keywords_T241.pyx diff --git a/Cython/Compiler/ExprNodes.py b/Cython/Compiler/ExprNodes.py index e6c3ed13..1fa22554 100644 --- a/Cython/Compiler/ExprNodes.py +++ b/Cython/Compiler/ExprNodes.py @@ -2527,7 +2527,11 @@ class GeneralCallNode(CallNode): self.keyword_args.analyse_types(env) if self.starstar_arg: self.starstar_arg.analyse_types(env) - self.function = self.function.coerce_to_pyobject(env) + if self.function.type is not py_object_type: + if hasattr(self.function, 'entry') and not self.function.entry.as_variable: + error(self.pos, "Keyword arguments not allowed in cdef functions.") + else: + self.function = self.function.coerce_to_pyobject(env) self.positional_args = \ self.positional_args.coerce_to_pyobject(env) if self.starstar_arg: diff --git a/tests/errors/e_cdef_keywords_T241.pyx b/tests/errors/e_cdef_keywords_T241.pyx new file mode 100644 index 00000000..8336b65a --- /dev/null +++ b/tests/errors/e_cdef_keywords_T241.pyx @@ -0,0 +1,19 @@ +cdef some_function(x, y): + pass + +cdef class A: + cdef some_method(self, x, y=1): + pass + +some_function(1, 2) +some_function(1, y=2) + +cdef A a = A() +a.some_method(1) +a.some_method(1, 2) +a.some_method(1, y=2) + +_ERRORS = u""" +:9:13: Keyword arguments not allowed in cdef functions. +:14:13: Keyword arguments not allowed in cdef functions. +""" -- 2.26.2