From 7e1933c77cf66f87f9bcf4eb9acdae0dfb524b4b Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sun, 14 Mar 2010 14:48:18 +0100 Subject: [PATCH] ticket #128: disable Cython type declarations in signatures of .py files --- Cython/Compiler/Parsing.py | 12 ++++++++++-- Cython/Compiler/Scanning.pxd | 1 + Cython/Compiler/Scanning.py | 2 ++ 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index 8abd96b6..3ee56367 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -2089,9 +2089,17 @@ def p_c_arg_decl(s, ctx, in_pyfunc, cmethod_flag = 0, nonempty = 0, kw_only = 0) pos = s.position() not_none = 0 default = None - base_type = p_c_base_type(s, cmethod_flag, nonempty = nonempty) + if s.in_python_file: + # empty type declaration + base_type = Nodes.CSimpleBaseTypeNode(pos, + name = None, module_path = [], + is_basic_c_type = 0, signed = 0, + complex = 0, longness = 0, + is_self_arg = cmethod_flag, templates = None) + else: + base_type = p_c_base_type(s, cmethod_flag, nonempty = nonempty) declarator = p_c_declarator(s, ctx, nonempty = nonempty) - if s.sy == 'not': + if s.sy == 'not' and not s.in_python_file: s.next() if s.sy == 'IDENT' and s.systring == 'None': s.next() diff --git a/Cython/Compiler/Scanning.pxd b/Cython/Compiler/Scanning.pxd index d98b7132..abcc5eea 100644 --- a/Cython/Compiler/Scanning.pxd +++ b/Cython/Compiler/Scanning.pxd @@ -13,6 +13,7 @@ cdef class PyrexScanner(Scanner): cdef public bint compile_time_eval cdef public bint compile_time_expr cdef public bint parse_comments + cdef public bint in_python_file cdef public source_encoding cdef set keywords cdef public list indentation_stack diff --git a/Cython/Compiler/Scanning.py b/Cython/Compiler/Scanning.py index bdbf46c4..fc07a0d1 100644 --- a/Cython/Compiler/Scanning.py +++ b/Cython/Compiler/Scanning.py @@ -255,8 +255,10 @@ class PyrexScanner(Scanner): self.parse_comments = parse_comments self.source_encoding = source_encoding if filename.is_python_file(): + self.in_python_file = True self.keywords = cython.set(py_reserved_words) else: + self.in_python_file = False self.keywords = cython.set(pyx_reserved_words) self.trace = trace_scanner self.indentation_stack = [0] -- 2.26.2