MCPcopy
hub / github.com/google/python-fire / _OneLineResult

Function _OneLineResult

fire/core.py:340–358  ·  view source on GitHub ↗

Returns result serialized to a single line string.

(result)

Source from the content-addressed store, hash-verified

338
339
340def _OneLineResult(result):
341 """Returns result serialized to a single line string."""
342 # TODO(dbieber): Ensure line is fewer than eg 120 characters.
343 if isinstance(result, str):
344 return str(result).replace('\n', ' ')
345
346 # TODO(dbieber): Show a small amount of usage information about the function
347 # or module if it fits cleanly on the line.
348 if inspect.isfunction(result):
349 return f'<function {result.__name__}>'
350
351 if inspect.ismodule(result):
352 return f'<module {result.__name__}>'
353
354 try:
355 # Don't force conversion to ascii.
356 return json.dumps(result, ensure_ascii=False)
357 except (TypeError, ValueError):
358 return str(result).replace('\n', ' ')
359
360
361def _Fire(component, args, parsed_flag_args, context, name=None):

Callers 2

_PrintResultFunction · 0.85
_DictAsStringFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected