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

Function make_safe_parse_float

Lib/tomllib/_parser.py:735–753  ·  view source on GitHub ↗

A decorator to make `parse_float` safe. `parse_float` must not return dicts or lists, because these types would be mixed with parsed TOML tables and arrays, thus confusing the parser. The returned decorated callable raises `ValueError` instead of returning illegal types.

(parse_float: ParseFloat)

Source from the content-addressed store, hash-verified

733
734
735def make_safe_parse_float(parse_float: ParseFloat) -> ParseFloat:
736 """A decorator to make `parse_float` safe.
737
738 `parse_float` must not return dicts or lists, because these types
739 would be mixed with parsed TOML tables and arrays, thus confusing
740 the parser. The returned decorated callable raises `ValueError`
741 instead of returning illegal types.
742 """
743 # The default `float` callable never returns illegal types. Optimize it.
744 if parse_float is float:
745 return float
746
747 def safe_parse_float(float_str: str) -> Any:
748 float_value = parse_float(float_str)
749 if isinstance(float_value, (dict, list)):
750 raise ValueError("parse_float must not return dicts or lists")
751 return float_value
752
753 return safe_parse_float

Callers 1

loadsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected