Skip to content

Commit c4f93fe

Browse files
committed
Always use repr() for displaying argument default values.
Closes issue bpython#153.
1 parent 81b6570 commit c4f93fe

File tree

4 files changed

+19
-7
lines changed

4 files changed

+19
-7
lines changed

bpython/cli.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -653,7 +653,7 @@ def mkargspec(self, topline, down):
653653
ln = len(str(i))
654654
kw = None
655655
if kwargs and k + 1 > len(args) - len(kwargs):
656-
kw = str(kwargs[k - (len(args) - len(kwargs))])
656+
kw = repr(kwargs[k - (len(args) - len(kwargs))])
657657
ln += len(kw) + 1
658658

659659
if ln + x >= w:
@@ -685,7 +685,7 @@ def mkargspec(self, topline, down):
685685
self.list_win.addstr(inspect.strseq(i, str), color)
686686
else:
687687
self.list_win.addstr(str(i), color)
688-
if kw:
688+
if kw is not None:
689689
self.list_win.addstr('=', punctuation_colpair)
690690
self.list_win.addstr(kw, get_colpair(self.config, 'token'))
691691
if k != len(args) -1:

bpython/gtk_.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def formatarg(self, name):
8383
return string
8484

8585
def formatvalue(self, value):
86-
return '=%s' % (value, )
86+
return '=%r' % (value, )
8787

8888

8989
class ExceptionDialog(gtk.MessageDialog):

bpython/inspection.py

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,18 @@ def __exit__(self, exc_type, exc_val, exc_tb):
100100
setattr(type_, '__getattr__', __getattr__)
101101
# /Dark magic
102102

103+
class _Repr(object):
104+
"""
105+
Helper for `fixlongargs()`: Returns the given value in `__repr__()`.
106+
"""
107+
108+
def __init__(self, value):
109+
self.value = value
110+
111+
def __repr__(self):
112+
return self.value
113+
114+
__str__ = __repr__
103115

104116
def parsekeywordpairs(signature):
105117
tokens = PythonLexer().get_tokens(signature)
@@ -164,8 +176,8 @@ def fixlongargs(f, argspec):
164176
kwparsed = parsekeywordpairs(signature)
165177

166178
for i, (key, value) in enumerate(zip(keys, values)):
167-
if len(str(value)) != len(kwparsed[key]):
168-
values[i] = kwparsed[key]
179+
if len(repr(value)) != len(kwparsed[key]):
180+
values[i] = _Repr(kwparsed[key])
169181

170182
argspec[3] = values
171183

bpython/urwid.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ def _populate_completion(self):
557557
# does clever wrapping. I do not (yet).
558558
for k, i in enumerate(args):
559559
if defaults and k + 1 > len(args) - len(defaults):
560-
kw = str(defaults[k - (len(args) - len(defaults))])
560+
kw = repr(defaults[k - (len(args) - len(defaults))])
561561
else:
562562
kw = None
563563

@@ -576,7 +576,7 @@ def _populate_completion(self):
576576
markup.append((color, inspect.strseq(i, str)))
577577
else:
578578
markup.append((color, str(i)))
579-
if kw:
579+
if kw is not None:
580580
markup.extend([('punctuation', '='),
581581
('token', kw)])
582582
if k != len(args) - 1:

0 commit comments

Comments
 (0)