X Tutup
Skip to content

Commit 7bb3b4a

Browse files
committed
Display tuple unpacking in argspec correctly.
This closes issue #138.
1 parent 61cd40a commit 7bb3b4a

File tree

3 files changed

+20
-3
lines changed

3 files changed

+20
-3
lines changed

bpython/cli.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ def log(x):
6666
f.write('%s\n' % (x,))
6767

6868
py3 = sys.version_info[0] == 3
69+
if not py3:
70+
import inspect
71+
6972
stdscr = None
7073

7174
def getpreferredencoding():
@@ -673,7 +676,13 @@ def mkargspec(self, topline, down):
673676
if k == in_arg or i == in_arg:
674677
color |= curses.A_BOLD
675678

676-
self.list_win.addstr(str(i), color)
679+
if not py3:
680+
# See issue #138: We need to format tuple unpacking correctly
681+
# We use the undocumented function inspection.strseq() for
682+
# that. Fortunately, that madness is gone in Python 3.
683+
self.list_win.addstr(inspect.strseq(i, str), color)
684+
else:
685+
self.list_win.addstr(str(i), color)
677686
if kw:
678687
self.list_win.addstr('=', punctuation_colpair)
679688
self.list_win.addstr(kw, get_colpair(self.config, 'token'))

bpython/repl.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ def complete(self, tab=False):
588588

589589
if not e and self.argspec:
590590
matches.extend(name + '=' for name in self.argspec[1][0]
591-
if name.startswith(cw))
591+
if isinstance(name, basestring) and name.startswith(cw))
592592
if py3:
593593
matches.extend(name + '=' for name in self.argspec[1][4]
594594
if name.startswith(cw))

bpython/urwid.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
import urwid
5252

5353
py3 = sys.version_info[0] == 3
54+
if not py3:
55+
import inspect
5456

5557
Parenthesis = Token.Punctuation.Parenthesis
5658

@@ -536,7 +538,13 @@ def _populate_completion(self):
536538
if k == in_arg or i == in_arg:
537539
color = 'bold ' + color
538540

539-
markup.append((color, str(i)))
541+
if not py3:
542+
# See issue #138: We need to format tuple unpacking correctly
543+
# We use the undocumented function inspection.strseq() for
544+
# that. Fortunately, that madness is gone in Python 3.
545+
markup.append((color, inspect.strseq(i, str)))
546+
else:
547+
markup.append((color, str(i)))
540548
if kw:
541549
markup.extend([('punctuation', '='),
542550
('token', kw)])

0 commit comments

Comments
 (0)
X Tutup