Skip to content

Commit bd7e8e4

Browse files
committed
Replacing argspec with namedtuples FuncProps, changed func signature to include arg_pos
1 parent 0ace2c4 commit bd7e8e4

File tree

1 file changed

+17
-19
lines changed

1 file changed

+17
-19
lines changed

bpython/curtsiesfrontend/replpainter.py

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -72,19 +72,17 @@ def matches_lines(rows, columns, matches, current, config, format):
7272
return matches_lines
7373

7474

75-
def formatted_argspec(argspec, columns, config):
75+
def formatted_argspec(funcprops, arg_pos, columns, config):
7676
# Pretty directly taken from bpython.cli
77-
is_bound_method = argspec[2]
78-
func = argspec[0]
79-
args = argspec[1][0]
80-
kwargs = argspec[1][3]
81-
_args = argspec[1][1] # *args
82-
_kwargs = argspec[1][2] # **kwargs
83-
is_bound_method = argspec[2]
84-
in_arg = argspec[3]
77+
func = funcprops.func
78+
args = funcprops.argspec.args
79+
kwargs = funcprops.argspec.defaults
80+
_args = funcprops.argspec.varargs
81+
_kwargs = funcprops.argspec.varkwargs
82+
is_bound_method = funcprops.is_bound_method
8583
if py3:
86-
kwonly = argspec[1][4]
87-
kwonly_defaults = argspec[1][5] or dict()
84+
kwonly = funcprops.argspec.kwonly
85+
kwonly_defaults = funcprops.argspec.kwonly_defaults or dict()
8886

8987
arg_color = func_for_letter(config.color_scheme['name'])
9088
func_color = func_for_letter(config.color_scheme['name'].swapcase())
@@ -95,16 +93,16 @@ def formatted_argspec(argspec, columns, config):
9593

9694
s = func_color(func) + arg_color(': (')
9795

98-
if is_bound_method and isinstance(in_arg, int):
96+
if is_bound_method and isinstance(arg_pos, int):
9997
# TODO what values could this have?
100-
in_arg += 1
98+
arg_pos += 1
10199

102100
for i, arg in enumerate(args):
103101
kw = None
104102
if kwargs and i >= len(args) - len(kwargs):
105103
kw = str(kwargs[i - (len(args) - len(kwargs))])
106-
color = token_color if in_arg in (i, arg) else arg_color
107-
if i == in_arg or arg == in_arg:
104+
color = token_color if arg_pos in (i, arg) else arg_color
105+
if i == arg_pos or arg == arg_pos:
108106
color = bolds[color]
109107

110108
if not py3:
@@ -135,7 +133,7 @@ def formatted_argspec(argspec, columns, config):
135133
for arg in kwonly:
136134
s += punctuation_color(', ')
137135
color = token_color
138-
if in_arg:
136+
if arg_pos:
139137
color = bolds[color]
140138
s += color(arg)
141139
default = kwonly_defaults.get(arg, marker)
@@ -159,13 +157,13 @@ def formatted_docstring(docstring, columns, config):
159157
for line in docstring.split('\n')), [])
160158

161159

162-
def paint_infobox(rows, columns, matches, argspec, match, docstring, config,
160+
def paint_infobox(rows, columns, matches, funcprops, arg_pos, match, docstring, config,
163161
format):
164-
"""Returns painted completions, argspec, match, docstring etc."""
162+
"""Returns painted completions, funcprops, match, docstring etc."""
165163
if not (rows and columns):
166164
return fsarray(0, 0)
167165
width = columns - 4
168-
lines = ((formatted_argspec(argspec, width, config) if argspec else []) +
166+
lines = ((formatted_argspec(funcprops, arg_pos, width, config) if funcprops else []) +
169167
(matches_lines(rows, width, matches, match, config, format)
170168
if matches else []) +
171169
(formatted_docstring(docstring, width, config)

0 commit comments

Comments
 (0)