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

Function normalize

Lib/test/test_tomllib/burntsushi.py:42–65  ·  view source on GitHub ↗

Normalize test objects. This normalizes primitive values (e.g. floats).

(obj: Any)

Source from the content-addressed store, hash-verified

40
41
42def normalize(obj: Any) -> Any:
43 """Normalize test objects.
44
45 This normalizes primitive values (e.g. floats)."""
46 if isinstance(obj, list):
47 return [normalize(item) for item in obj]
48 if isinstance(obj, dict):
49 if "type" in obj and "value" in obj:
50 type_ = obj["type"]
51 value = obj["value"]
52 if type_ == "float":
53 norm_value = _normalize_float_str(value)
54 elif type_ in {"datetime", "datetime-local"}:
55 norm_value = _normalize_datetime_str(value)
56 elif type_ == "time-local":
57 norm_value = _normalize_localtime_str(value)
58 else:
59 norm_value = value
60
61 if type_ == "array":
62 return [normalize(item) for item in value]
63 return {"type": type_, "value": norm_value}
64 return {k: normalize(v) for k, v in obj.items()}
65 raise AssertionError("Burntsushi fixtures should be dicts/lists only")
66
67
68def _normalize_datetime_str(dt_str: str) -> str:

Callers 5

normMethod · 0.50
test_normalizeMethod · 0.50

Calls 4

_normalize_float_strFunction · 0.85
_normalize_datetime_strFunction · 0.85
_normalize_localtime_strFunction · 0.85
itemsMethod · 0.45

Tested by 5

normMethod · 0.40
test_normalizeMethod · 0.40

Used in the wild real call sites across dependent graphs

searching dependent graphs…