From 1f83af9624e072c80035eb615fae85e7aca425b7 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Sun, 18 Oct 2009 19:31:53 +0200 Subject: [PATCH] fix default string value representation in auto-embedded signatures --- Cython/Compiler/AutoDocTransforms.py | 23 ++++++++++++++++------- tests/run/embedsignatures.pyx | 4 ---- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/Cython/Compiler/AutoDocTransforms.py b/Cython/Compiler/AutoDocTransforms.py index ed53d8d3..c41bbbf1 100644 --- a/Cython/Compiler/AutoDocTransforms.py +++ b/Cython/Compiler/AutoDocTransforms.py @@ -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 '' diff --git a/tests/run/embedsignatures.pyx b/tests/run/embedsignatures.pyx index 2f24f723..fa93ad3b 100644 --- a/tests/run/embedsignatures.pyx +++ b/tests/run/embedsignatures.pyx @@ -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): -- 2.26.2