From: Gregory Ewing Date: Fri, 16 May 2008 11:50:02 +0000 (+1200) Subject: Base class not needed in forward extension class declaration X-Git-Tag: 0.9.8rc1~17 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=5f13fdb25a184bc82a2e5dac2663627aeaa5168f;p=cython.git Base class not needed in forward extension class declaration + +Enhancements: + + - It is no longer necessary to specify the base class of an + extension type in a forward declaration. Also, if the class is + defined in a .pxd file, the base class only needs to be specified + in the .pxd file, not the .pyx file. + [Arc Riley] - --- diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index 8127e534..26f2335f 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -906,19 +906,24 @@ class ModuleScope(Scope): module_name, base_type, objstruct_cname, typeobj_cname, visibility, typedef_flag, api): # - # Look for previous declaration as a type + # Look for previous declaration as a type # entry = self.lookup_here(name) if entry: type = entry.type if not (entry.is_type and type.is_extension_type): - entry = None # Will cause an error when we redeclare it + entry = None # Will cause redeclaration and produce an error else: - self.check_previous_typedef_flag(entry, typedef_flag, pos) - if base_type != type.base_type: - error(pos, "Base type does not match previous declaration") + scope = type.scope + if typedef_flag and scope.defined: + self.check_previous_typedef_flag(entry, typedef_flag, pos) + if (scope and scope.defined) or (base_type and type.base_type): + if base_type and base_type is not type.base_type: + error(pos, "Base type does not match previous declaration") + if base_type and not type.base_type: + type.base_type = base_type # - # Make a new entry if needed + # Make a new entry if needed # if not entry: type = PyrexTypes.PyExtensionType(name, typedef_flag, base_type) @@ -940,7 +945,7 @@ class ModuleScope(Scope): self.attach_var_entry_to_c_class(entry) self.c_class_entries.append(entry) # - # Check for re-definition and create scope if needed + # Check for re-definition and create scope if needed # if not type.scope: if defining or implementing: @@ -958,7 +963,7 @@ class ModuleScope(Scope): elif implementing and type.scope.implemented: error(pos, "C class '%s' already implemented" % name) # - # Fill in options, checking for compatibility with any previous declaration + # Fill in options, checking for compatibility with any previous declaration # if defining: entry.defined_in_pxd = 1