MCPcopy Index your code
hub / github.com/RustPython/RustPython / format

Method format

Lib/inspect.py:3258–3316  ·  view source on GitHub ↗

Create a string representation of the Signature object. If *max_width* integer is passed, signature will try to fit into the *max_width*. If signature is longer than *max_width*, all parameters will be on separate lines. If *quote_annotation_strings* is Fals

(self, *, max_width=None, quote_annotation_strings=True)

Source from the content-addressed store, hash-verified

3256 return self.format()
3257
3258 def format(self, *, max_width=None, quote_annotation_strings=True):
3259 """Create a string representation of the Signature object.
3260
3261 If *max_width* integer is passed,
3262 signature will try to fit into the *max_width*.
3263 If signature is longer than *max_width*,
3264 all parameters will be on separate lines.
3265
3266 If *quote_annotation_strings* is False, annotations
3267 in the signature are displayed without opening and closing quotation
3268 marks. This is useful when the signature was created with the
3269 STRING format or when ``from __future__ import annotations`` was used.
3270 """
3271 result = []
3272 render_pos_only_separator = False
3273 render_kw_only_separator = True
3274 for param in self.parameters.values():
3275 formatted = param._format(quote_annotation_strings=quote_annotation_strings)
3276
3277 kind = param.kind
3278
3279 if kind == _POSITIONAL_ONLY:
3280 render_pos_only_separator = True
3281 elif render_pos_only_separator:
3282 # It's not a positional-only parameter, and the flag
3283 # is set to 'True' (there were pos-only params before.)
3284 result.append('/')
3285 render_pos_only_separator = False
3286
3287 if kind == _VAR_POSITIONAL:
3288 # OK, we have an '*args'-like parameter, so we won't need
3289 # a '*' to separate keyword-only arguments
3290 render_kw_only_separator = False
3291 elif kind == _KEYWORD_ONLY and render_kw_only_separator:
3292 # We have a keyword-only parameter to render and we haven't
3293 # rendered an '*args'-like parameter before, so add a '*'
3294 # separator to the parameters list ("foo(arg1, *, arg2)" case)
3295 result.append('*')
3296 # This condition should be only triggered once, so
3297 # reset the flag
3298 render_kw_only_separator = False
3299
3300 result.append(formatted)
3301
3302 if render_pos_only_separator:
3303 # There were only positional-only parameters, hence the
3304 # flag was not reset to 'False'
3305 result.append('/')
3306
3307 rendered = '({})'.format(', '.join(result))
3308 if max_width is not None and len(rendered) > max_width:
3309 rendered = '(\n {}\n)'.format(',\n '.join(result))
3310
3311 if self.return_annotation is not _empty:
3312 anno = formatannotation(self.return_annotation,
3313 quote_annotation_strings=quote_annotation_strings)
3314 rendered += ' -> {}'.format(anno)
3315

Callers 15

__str__Method · 0.95
test_demoFunction · 0.45
wait_for_portFunction · 0.45
Time2InternaldateFunction · 0.45
_find_implFunction · 0.45
_strptimeFunction · 0.45
create_archiveFunction · 0.45
mainFunction · 0.45
__repr__Method · 0.45
_fspathFunction · 0.45
__repr__Method · 0.45
pickletools.pyFile · 0.45

Calls 6

lenFunction · 0.85
formatannotationFunction · 0.85
valuesMethod · 0.45
_formatMethod · 0.45
appendMethod · 0.45
joinMethod · 0.45

Tested by 11

test_demoFunction · 0.36
wait_for_portFunction · 0.36
create_test_functionFunction · 0.36
generate_slicesFunction · 0.36
__init__Method · 0.36
rowMethod · 0.36
addSkipMethod · 0.36
__exit__Method · 0.36
_typedFunction · 0.36
test_all_slicesFunction · 0.36