From: Lisandro Dalcin Date: Tue, 9 Mar 2010 01:43:00 +0000 (-0300) Subject: change display of typedef types, use plain name instead of qualified name X-Git-Tag: 0.13.beta0~2^2~97^2~1 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=b93bc72362833b9f14c1be2e6a18485520d2eca6;p=cython.git change display of typedef types, use plain name instead of qualified name --- diff --git a/Cython/Compiler/PyrexTypes.py b/Cython/Compiler/PyrexTypes.py index 2e6bdc05..1ca8e4cf 100755 --- a/Cython/Compiler/PyrexTypes.py +++ b/Cython/Compiler/PyrexTypes.py @@ -164,13 +164,13 @@ class PyrexType(BaseType): return 1 -def create_typedef_type(cname, base_type, is_external=0): +def create_typedef_type(name, base_type, cname, is_external=0): if base_type.is_complex: if is_external: raise ValueError("Complex external typedefs not supported") return base_type else: - return CTypedefType(cname, base_type, is_external) + return CTypedefType(name, base_type, cname, is_external) class CTypedefType(BaseType): # @@ -180,6 +180,7 @@ class CTypedefType(BaseType): # HERE IS DELEGATED! # # qualified_name string + # typedef_name string # typedef_cname string # typedef_base_type PyrexType # typedef_is_external bool @@ -191,8 +192,9 @@ class CTypedefType(BaseType): from_py_utility_code = None - def __init__(self, cname, base_type, is_external=0): + def __init__(self, name, base_type, cname, is_external=0): assert not base_type.is_complex + self.typedef_name = name self.typedef_cname = cname self.typedef_base_type = base_type self.typedef_is_external = is_external @@ -214,19 +216,12 @@ class CTypedefType(BaseType): def declaration_code(self, entity_code, for_display = 0, dll_linkage = None, pyrex = 0): - name = self.declaration_name(for_display, pyrex) if pyrex or for_display: - base_code = name + base_code = self.typedef_name else: - base_code = public_decl(name, dll_linkage) + base_code = public_decl(self.typedef_cname, dll_linkage) return self.base_declaration_code(base_code, entity_code) - def declaration_name(self, for_display = 0, pyrex = 0): - if pyrex or for_display: - return self.qualified_name - else: - return self.typedef_cname - def as_argument_type(self): return self @@ -242,7 +237,7 @@ class CTypedefType(BaseType): return "" % self.typedef_cname def __str__(self): - return self.declaration_name(for_display = 1) + return self.typedef_name def _create_utility_code(self, template_utility_code, template_function_name): diff --git a/Cython/Compiler/Symtab.py b/Cython/Compiler/Symtab.py index 13395144..8ae43751 100644 --- a/Cython/Compiler/Symtab.py +++ b/Cython/Compiler/Symtab.py @@ -359,7 +359,8 @@ class Scope(object): else: cname = self.mangle(Naming.type_prefix, name) try: - type = PyrexTypes.create_typedef_type(cname, base_type, (visibility == 'extern')) + type = PyrexTypes.create_typedef_type(name, base_type, cname, + (visibility == 'extern')) except ValueError, e: error(pos, e.message) type = PyrexTypes.error_type diff --git a/tests/errors/e_excvalfunctype.pyx b/tests/errors/e_excvalfunctype.pyx index 3f6b6154..44b8c050 100644 --- a/tests/errors/e_excvalfunctype.pyx +++ b/tests/errors/e_excvalfunctype.pyx @@ -7,6 +7,6 @@ cdef spamfunc spam grail = spam # type mismatch spam = grail # type mismatch _ERRORS = u""" -7:28: Cannot assign type 'e_excvalfunctype.spamfunc' to 'e_excvalfunctype.grailfunc' -8:28: Cannot assign type 'e_excvalfunctype.grailfunc' to 'e_excvalfunctype.spamfunc' +7:28: Cannot assign type 'spamfunc' to 'grailfunc' +8:28: Cannot assign type 'grailfunc' to 'spamfunc' """ diff --git a/tests/run/bufaccess.pyx b/tests/run/bufaccess.pyx index 3f76acbe..24a74a97 100644 --- a/tests/run/bufaccess.pyx +++ b/tests/run/bufaccess.pyx @@ -798,7 +798,7 @@ def printbuf_td_cy_int(object[td_cy_int] buf, shape): >>> printbuf_td_cy_int(ShortMockBuffer(None, range(3)), (3,)) Traceback (most recent call last): ... - ValueError: Buffer dtype mismatch, expected 'bufaccess.td_cy_int' but got 'short' + ValueError: Buffer dtype mismatch, expected 'td_cy_int' but got 'short' """ cdef int i for i in range(shape[0]): @@ -813,7 +813,7 @@ def printbuf_td_h_short(object[td_h_short] buf, shape): >>> printbuf_td_h_short(IntMockBuffer(None, range(3)), (3,)) Traceback (most recent call last): ... - ValueError: Buffer dtype mismatch, expected 'bufaccess.td_h_short' but got 'int' + ValueError: Buffer dtype mismatch, expected 'td_h_short' but got 'int' """ cdef int i for i in range(shape[0]): @@ -828,7 +828,7 @@ def printbuf_td_h_cy_short(object[td_h_cy_short] buf, shape): >>> printbuf_td_h_cy_short(IntMockBuffer(None, range(3)), (3,)) Traceback (most recent call last): ... - ValueError: Buffer dtype mismatch, expected 'bufaccess.td_h_cy_short' but got 'int' + ValueError: Buffer dtype mismatch, expected 'td_h_cy_short' but got 'int' """ cdef int i for i in range(shape[0]): @@ -843,7 +843,7 @@ def printbuf_td_h_ushort(object[td_h_ushort] buf, shape): >>> printbuf_td_h_ushort(ShortMockBuffer(None, range(3)), (3,)) Traceback (most recent call last): ... - ValueError: Buffer dtype mismatch, expected 'bufaccess.td_h_ushort' but got 'short' + ValueError: Buffer dtype mismatch, expected 'td_h_ushort' but got 'short' """ cdef int i for i in range(shape[0]): @@ -858,7 +858,7 @@ def printbuf_td_h_double(object[td_h_double] buf, shape): >>> printbuf_td_h_double(FloatMockBuffer(None, [0.25, 1, 3.125]), (3,)) Traceback (most recent call last): ... - ValueError: Buffer dtype mismatch, expected 'bufaccess.td_h_double' but got 'float' + ValueError: Buffer dtype mismatch, expected 'td_h_double' but got 'float' """ cdef int i for i in range(shape[0]): diff --git a/tests/run/embedsignatures.pyx b/tests/run/embedsignatures.pyx index fa93ad3b..3fafdbed 100644 --- a/tests/run/embedsignatures.pyx +++ b/tests/run/embedsignatures.pyx @@ -135,6 +135,12 @@ __doc__ = ur""" >>> print (f_D.__doc__) f_D(long double D) -> long double + >>> print (f_my_i.__doc__) + f_my_i(MyInt i) -> MyInt + + >>> print (f_my_f.__doc__) + f_my_f(MyFloat f) -> MyFloat + """ cdef class Ext: @@ -279,3 +285,11 @@ cpdef double f_d(double d): cpdef long double f_D(long double D): return D + +ctypedef int MyInt +cpdef MyInt f_my_i(MyInt i): + return i + +ctypedef float MyFloat +cpdef MyFloat f_my_f(MyFloat f): + return f