MCPcopy Create free account
hub / github.com/IBM/mcp-cli / _try_parse_number

Method _try_parse_number

src/mcp_cli/chat/tool_processor.py:1383–1400  ·  view source on GitHub ↗

Try to parse a string as a number, return original if not possible.

(self, text: str)

Source from the content-addressed store, hash-verified

1381 return repr_str
1382
1383 def _try_parse_number(self, text: str) -> Any:
1384 """Try to parse a string as a number, return original if not possible."""
1385 if not text or not isinstance(text, str):
1386 return text
1387
1388 text = text.strip()
1389
1390 # Handle "None" string
1391 if text in ("None", "null", ""):
1392 return None
1393
1394 # Try float (handles integers too)
1395 try:
1396 return float(text)
1397 except (ValueError, TypeError):
1398 pass
1399
1400 return text
1401
1402 def _format_tool_response(self, result: Any) -> str:
1403 """Format tool response for conversation history."""

Callers 15

_extract_result_valueMethod · 0.95
_parse_content_reprMethod · 0.95
test_integer_stringMethod · 0.80
test_float_stringMethod · 0.80
test_non_numericMethod · 0.80
test_none_inputMethod · 0.80
test_not_stringMethod · 0.80
test_string_noneMethod · 0.80
test_string_nullMethod · 0.80
test_whitespaceMethod · 0.80

Calls

no outgoing calls

Tested by 15

test_integer_stringMethod · 0.64
test_float_stringMethod · 0.64
test_non_numericMethod · 0.64
test_none_inputMethod · 0.64
test_not_stringMethod · 0.64
test_string_noneMethod · 0.64
test_string_nullMethod · 0.64
test_whitespaceMethod · 0.64