Commits

Andreas Stührk committed 9fb8524

Always use repr() for displaying argument default values.

Closes issue #153.

Comments (0)

Files changed (4)

             ln = len(str(i))
             kw = None
             if kwargs and k + 1 > len(args) - len(kwargs):
-                kw = str(kwargs[k - (len(args) - len(kwargs))])
+                kw = repr(kwargs[k - (len(args) - len(kwargs))])
                 ln += len(kw) + 1
 
             if ln + x >= w:
                 self.list_win.addstr(inspect.strseq(i, str), color)
             else:
                 self.list_win.addstr(str(i), color)
-            if kw:
+            if kw is not None:
                 self.list_win.addstr('=', punctuation_colpair)
                 self.list_win.addstr(kw, get_colpair(self.config, 'token'))
             if k != len(args) -1:
         return string
 
     def formatvalue(self, value):
-        return '=%s' % (value, )
+        return '=%r' % (value, )
 
 
 class ExceptionDialog(gtk.MessageDialog):

bpython/inspection.py

             setattr(type_, '__getattr__', __getattr__)
         # /Dark magic
 
+class _Repr(object):
+    """
+    Helper for `fixlongargs()`: Returns the given value in `__repr__()`.
+    """
+
+    def __init__(self, value):
+        self.value = value
+
+    def __repr__(self):
+        return self.value
+
+    __str__ = __repr__
 
 def parsekeywordpairs(signature):
     tokens = PythonLexer().get_tokens(signature)
     kwparsed = parsekeywordpairs(signature)
 
     for i, (key, value) in enumerate(zip(keys, values)):
-        if len(str(value)) != len(kwparsed[key]):
-            values[i] = kwparsed[key]
+        if len(repr(value)) != len(kwparsed[key]):
+            values[i] = _Repr(kwparsed[key])
 
     argspec[3] = values
 
                 # does clever wrapping. I do not (yet).
                 for k, i in enumerate(args):
                     if defaults and k + 1 > len(args) - len(defaults):
-                        kw = str(defaults[k - (len(args) - len(defaults))])
+                        kw = repr(defaults[k - (len(args) - len(defaults))])
                     else:
                         kw = None
 
                         markup.append((color, inspect.strseq(i, str)))
                     else:
                         markup.append((color, str(i)))
-                    if kw:
+                    if kw is not None:
                         markup.extend([('punctuation', '='),
                                        ('token', kw)])
                     if k != len(args) - 1: