MCPcopy Create free account
hub / github.com/bpython/bpython / formatted_argspec

Function formatted_argspec

bpython/curtsiesfrontend/replpainter.py:92–163  ·  view source on GitHub ↗
(funcprops, arg_pos, columns, config)

Source from the content-addressed store, hash-verified

90
91
92def formatted_argspec(funcprops, arg_pos, columns, config):
93 # Pretty directly taken from bpython.cli
94 func = funcprops.func
95 args = funcprops.argspec.args
96 kwargs = funcprops.argspec.defaults
97 _args = funcprops.argspec.varargs
98 _kwargs = funcprops.argspec.varkwargs
99 is_bound_method = funcprops.is_bound_method
100 kwonly = funcprops.argspec.kwonly
101 kwonly_defaults = funcprops.argspec.kwonly_defaults or dict()
102
103 arg_color = func_for_letter(config.color_scheme["name"])
104 func_color = func_for_letter(config.color_scheme["name"].swapcase())
105 punctuation_color = func_for_letter(config.color_scheme["punctuation"])
106 token_color = func_for_letter(config.color_scheme["token"])
107 bolds = {
108 token_color: lambda x: bold(token_color(x)),
109 arg_color: lambda x: bold(arg_color(x)),
110 }
111
112 s = func_color(func) + arg_color(": (")
113
114 if is_bound_method and isinstance(arg_pos, int):
115 # TODO what values could this have?
116 arg_pos += 1
117
118 for i, arg in enumerate(args):
119 kw = None
120 if kwargs and i >= len(args) - len(kwargs):
121 kw = str(kwargs[i - (len(args) - len(kwargs))])
122 color = token_color if arg_pos in (i, arg) else arg_color
123 if i == arg_pos or arg == arg_pos:
124 color = bolds[color]
125
126 s += color(arg)
127
128 if kw is not None:
129 s += punctuation_color("=")
130 s += token_color(kw)
131
132 if i != len(args) - 1:
133 s += punctuation_color(", ")
134
135 if _args:
136 if args:
137 s += punctuation_color(", ")
138 s += token_color(f"*{_args}")
139
140 if kwonly:
141 if not _args:
142 if args:
143 s += punctuation_color(", ")
144 s += punctuation_color("*")
145 marker = object()
146 for arg in kwonly:
147 s += punctuation_color(", ")
148 color = token_color
149 if arg_pos:

Callers 1

paint_infoboxFunction · 0.85

Calls 1

func_for_letterFunction · 0.85

Tested by

no test coverage detected