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

Function convert

Lib/test/test_tomllib/burntsushi.py:11–39  ·  view source on GitHub ↗
(obj)

Source from the content-addressed store, hash-verified

9
10
11def convert(obj):
12 if isinstance(obj, str):
13 return {"type": "string", "value": obj}
14 elif isinstance(obj, bool):
15 return {"type": "bool", "value": str(obj).lower()}
16 elif isinstance(obj, int):
17 return {"type": "integer", "value": str(obj)}
18 elif isinstance(obj, float):
19 return {"type": "float", "value": _normalize_float_str(str(obj))}
20 elif isinstance(obj, datetime.datetime):
21 val = _normalize_datetime_str(obj.isoformat())
22 if obj.tzinfo:
23 return {"type": "datetime", "value": val}
24 return {"type": "datetime-local", "value": val}
25 elif isinstance(obj, datetime.time):
26 return {
27 "type": "time-local",
28 "value": _normalize_localtime_str(str(obj)),
29 }
30 elif isinstance(obj, datetime.date):
31 return {
32 "type": "date-local",
33 "value": str(obj),
34 }
35 elif isinstance(obj, list):
36 return [convert(i) for i in obj]
37 elif isinstance(obj, dict):
38 return {k: convert(v) for k, v in obj.items()}
39 raise Exception("unsupported type")
40
41
42def normalize(obj: Any) -> Any:

Callers

nothing calls this directly

Calls 7

strFunction · 0.85
_normalize_float_strFunction · 0.85
_normalize_datetime_strFunction · 0.85
_normalize_localtime_strFunction · 0.85
lowerMethod · 0.45
isoformatMethod · 0.45
itemsMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…