fix default string value representation in auto-embedded signatures
authorStefan Behnel <scoder@users.berlios.de>
Sun, 18 Oct 2009 17:31:53 +0000 (19:31 +0200)
committerStefan Behnel <scoder@users.berlios.de>
Sun, 18 Oct 2009 17:31:53 +0000 (19:31 +0200)
Cython/Compiler/AutoDocTransforms.py
tests/run/embedsignatures.pyx

index ed53d8d305f45a668491b56c1365db60ba0d7a8c..c41bbbf1620b7387d7526b2158d657964825ff71 100644 (file)
@@ -3,9 +3,7 @@ from Cython.Compiler.Nodes import DefNode, CFuncDefNode
 from Cython.Compiler.Errors import CompileError
 from Cython.Compiler.StringEncoding import EncodedString
 from Cython.Compiler import Options
-from Cython.Compiler import PyrexTypes
-
-
+from Cython.Compiler import PyrexTypes, ExprNodes
 
 class EmbedSignature(CythonTransform):
 
@@ -16,15 +14,26 @@ class EmbedSignature(CythonTransform):
         self.class_node = None
 
     def _fmt_arg_defv(self, arg):
-        if not arg.default:
+        default_val = arg.default
+        if not default_val:
             return None
         try:
             denv = self.denv  # XXX
-            ctval = arg.default.compile_time_value(self.denv)
-            return '%r' % ctval
+            ctval = default_val.compile_time_value(self.denv)
+            repr_val = '%r' % ctval
+            if isinstance(default_val, ExprNodes.UnicodeNode):
+                if repr_val[:1] != 'u':
+                    return u'u%s' % repr_val
+            elif isinstance(default_val, ExprNodes.BytesNode):
+                if repr_val[:1] != 'b':
+                    return u'b%s' % repr_val
+            elif isinstance(default_val, ExprNodes.StringNode):
+                if repr_val[:1] in ('u', 'b'):
+                    repr_val[1:]
+            return repr_val
         except Exception:
             try:
-                return arg.default.name # XXX
+                return default_val.name # XXX
             except AttributeError:
                 return '<???>'
 
index 2f24f7235c5f99e3c5bfaee7907000bc8d41c1e5..fa93ad3b46a809c5679525cc2ca2382075cd3b84 100644 (file)
@@ -137,10 +137,6 @@ __doc__ = ur"""
 
 """
 
-import sys
-if sys.version_info[0] >= 3:
-    __doc__ = __doc__.replace(u"u'spam'", u"'spam'")
-
 cdef class Ext:
 
     def __init__(self, a, b, c=None):