MCPcopy Index your code
hub / github.com/python/cpython / make_safe_parse_float

Function make_safe_parse_float

Lib/tomllib/_parser.py:740–758  ·  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

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

Callers 1

loadsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…