From fcff8775c7b7a6817c2d8b4d107a0f2de9ee0497 Mon Sep 17 00:00:00 2001 From: Yujong Lee Date: Wed, 23 Sep 2026 19:44:05 -0700 Subject: [PATCH] feat(python-compat): reproduce int(), float(), and pydantic's lax int number::int and number::float follow CPython's conversions of plain data, and pydantic::lax_int follows TypeAdapter(int) in lax mode, which LiteLLM's usage models apply to provider numbers. The fixture generator records each conversion's result or exception class for every corpus row, now including numeric text Co-Authored-By: Claude Opus 5.5 --- litellm-rust/Cargo.lock | 1 + litellm-rust/crates/python-compat/Cargo.toml | 1 + .../python-compat/generated/values.json | 1441 +++++++++++++++++ .../scripts/generate_fixtures.py | 48 +- .../crates/python-compat/src/error.rs | 22 + litellm-rust/crates/python-compat/src/lib.rs | 6 +- .../crates/python-compat/src/number.rs | 118 ++ .../crates/python-compat/src/pydantic.rs | 54 + .../crates/python-compat/tests/fixtures.rs | 54 +- 9 files changed, 1738 insertions(+), 7 deletions(-) create mode 100644 litellm-rust/crates/python-compat/src/number.rs create mode 100644 litellm-rust/crates/python-compat/src/pydantic.rs diff --git a/litellm-rust/Cargo.lock b/litellm-rust/Cargo.lock index 534f6b548db..0d991b7b72e 100644 --- a/litellm-rust/Cargo.lock +++ b/litellm-rust/Cargo.lock @@ -3159,6 +3159,7 @@ dependencies = [ "serde", "serde-pickle", "serde_json", + "strum", "thiserror 2.0.19", ] diff --git a/litellm-rust/crates/python-compat/Cargo.toml b/litellm-rust/crates/python-compat/Cargo.toml index 2ab6fb29843..5d97e411488 100644 --- a/litellm-rust/crates/python-compat/Cargo.toml +++ b/litellm-rust/crates/python-compat/Cargo.toml @@ -12,6 +12,7 @@ num-traits = "0.2" serde.workspace = true serde-pickle = "1.2" serde_json = { workspace = true, features = ["preserve_order"] } +strum.workspace = true thiserror.workspace = true [dev-dependencies] diff --git a/litellm-rust/crates/python-compat/generated/values.json b/litellm-rust/crates/python-compat/generated/values.json index 7f7e1e35a7d..49a856c0c9e 100644 --- a/litellm-rust/crates/python-compat/generated/values.json +++ b/litellm-rust/crates/python-compat/generated/values.json @@ -9,6 +9,15 @@ "repr": "None", "str": "None", "truthy": false, + "int": { + "error": "TypeError" + }, + "float": { + "error": "TypeError" + }, + "lax_int": { + "error": "ValueError" + }, "json": "null", "pickle": { "0": "4e2e", @@ -28,6 +37,15 @@ "repr": "True", "str": "True", "truthy": true, + "int": { + "value": "1" + }, + "float": { + "value": "1.0" + }, + "lax_int": { + "value": "1" + }, "json": "true", "pickle": { "0": "4930310a2e", @@ -47,6 +65,15 @@ "repr": "False", "str": "False", "truthy": false, + "int": { + "value": "0" + }, + "float": { + "value": "0.0" + }, + "lax_int": { + "value": "0" + }, "json": "false", "pickle": { "0": "4930300a2e", @@ -66,6 +93,15 @@ "repr": "0", "str": "0", "truthy": false, + "int": { + "value": "0" + }, + "float": { + "value": "0.0" + }, + "lax_int": { + "value": "0" + }, "json": "0", "pickle": { "0": "49300a2e", @@ -85,6 +121,15 @@ "repr": "-7", "str": "-7", "truthy": true, + "int": { + "value": "-7" + }, + "float": { + "value": "-7.0" + }, + "lax_int": { + "value": "-7" + }, "json": "-7", "pickle": { "0": "492d370a2e", @@ -104,6 +149,15 @@ "repr": "9223372036854775807", "str": "9223372036854775807", "truthy": true, + "int": { + "value": "9223372036854775807" + }, + "float": { + "value": "9.223372036854776e+18" + }, + "lax_int": { + "value": "9223372036854775807" + }, "json": "9223372036854775807", "pickle": { "0": "4c393232333337323033363835343737353830374c0a2e", @@ -123,6 +177,15 @@ "repr": "-9223372036854775808", "str": "-9223372036854775808", "truthy": true, + "int": { + "value": "-9223372036854775808" + }, + "float": { + "value": "-9.223372036854776e+18" + }, + "lax_int": { + "value": "-9223372036854775808" + }, "json": "-9223372036854775808", "pickle": { "0": "4c2d393232333337323033363835343737353830384c0a2e", @@ -142,6 +205,15 @@ "repr": "18446744073709551616", "str": "18446744073709551616", "truthy": true, + "int": { + "value": "18446744073709551616" + }, + "float": { + "value": "1.8446744073709552e+19" + }, + "lax_int": { + "value": "18446744073709551616" + }, "json": "18446744073709551616", "pickle": { "0": "4c31383434363734343037333730393535313631364c0a2e", @@ -161,6 +233,15 @@ "repr": "-1180591620717411303424", "str": "-1180591620717411303424", "truthy": true, + "int": { + "value": "-1180591620717411303424" + }, + "float": { + "value": "-1.1805916207174113e+21" + }, + "lax_int": { + "value": "-1180591620717411303424" + }, "json": "-1180591620717411303424", "pickle": { "0": "4c2d313138303539313632303731373431313330333432344c0a2e", @@ -180,6 +261,15 @@ "repr": "0.0", "str": "0.0", "truthy": false, + "int": { + "value": "0" + }, + "float": { + "value": "0.0" + }, + "lax_int": { + "value": "0" + }, "json": "0.0", "pickle": { "0": "46302e300a2e", @@ -199,6 +289,15 @@ "repr": "-0.0", "str": "-0.0", "truthy": false, + "int": { + "value": "0" + }, + "float": { + "value": "-0.0" + }, + "lax_int": { + "value": "0" + }, "json": "-0.0", "pickle": { "0": "462d302e300a2e", @@ -218,6 +317,15 @@ "repr": "0.2", "str": "0.2", "truthy": true, + "int": { + "value": "0" + }, + "float": { + "value": "0.2" + }, + "lax_int": { + "error": "ValueError" + }, "json": "0.2", "pickle": { "0": "46302e320a2e", @@ -237,6 +345,15 @@ "repr": "1.0", "str": "1.0", "truthy": true, + "int": { + "value": "1" + }, + "float": { + "value": "1.0" + }, + "lax_int": { + "value": "1" + }, "json": "1.0", "pickle": { "0": "46312e300a2e", @@ -256,6 +373,15 @@ "repr": "-1.5", "str": "-1.5", "truthy": true, + "int": { + "value": "-1" + }, + "float": { + "value": "-1.5" + }, + "lax_int": { + "error": "ValueError" + }, "json": "-1.5", "pickle": { "0": "462d312e350a2e", @@ -275,6 +401,15 @@ "repr": "0.30000000000000004", "str": "0.30000000000000004", "truthy": true, + "int": { + "value": "0" + }, + "float": { + "value": "0.30000000000000004" + }, + "lax_int": { + "error": "ValueError" + }, "json": "0.30000000000000004", "pickle": { "0": "46302e33303030303030303030303030303030340a2e", @@ -294,6 +429,15 @@ "repr": "123456789.123", "str": "123456789.123", "truthy": true, + "int": { + "value": "123456789" + }, + "float": { + "value": "123456789.123" + }, + "lax_int": { + "error": "ValueError" + }, "json": "123456789.123", "pickle": { "0": "463132333435363738392e3132330a2e", @@ -313,6 +457,15 @@ "repr": "1000000000000000.0", "str": "1000000000000000.0", "truthy": true, + "int": { + "value": "1000000000000000" + }, + "float": { + "value": "1000000000000000.0" + }, + "lax_int": { + "value": "1000000000000000" + }, "json": "1000000000000000.0", "pickle": { "0": "46313030303030303030303030303030302e300a2e", @@ -332,6 +485,15 @@ "repr": "1e+16", "str": "1e+16", "truthy": true, + "int": { + "value": "10000000000000000" + }, + "float": { + "value": "1e+16" + }, + "lax_int": { + "value": "10000000000000000" + }, "json": "1e+16", "pickle": { "0": "4631652b31360a2e", @@ -351,6 +513,15 @@ "repr": "1.5e+16", "str": "1.5e+16", "truthy": true, + "int": { + "value": "15000000000000000" + }, + "float": { + "value": "1.5e+16" + }, + "lax_int": { + "value": "15000000000000000" + }, "json": "1.5e+16", "pickle": { "0": "46312e35652b31360a2e", @@ -370,6 +541,15 @@ "repr": "9999999999999998.0", "str": "9999999999999998.0", "truthy": true, + "int": { + "value": "9999999999999998" + }, + "float": { + "value": "9999999999999998.0" + }, + "lax_int": { + "value": "9999999999999998" + }, "json": "9999999999999998.0", "pickle": { "0": "46393939393939393939393939393939382e300a2e", @@ -389,6 +569,15 @@ "repr": "0.0001", "str": "0.0001", "truthy": true, + "int": { + "value": "0" + }, + "float": { + "value": "0.0001" + }, + "lax_int": { + "error": "ValueError" + }, "json": "0.0001", "pickle": { "0": "46302e303030310a2e", @@ -408,6 +597,15 @@ "repr": "1e-05", "str": "1e-05", "truthy": true, + "int": { + "value": "0" + }, + "float": { + "value": "1e-05" + }, + "lax_int": { + "error": "ValueError" + }, "json": "1e-05", "pickle": { "0": "4631652d30350a2e", @@ -427,6 +625,15 @@ "repr": "1.25e-07", "str": "1.25e-07", "truthy": true, + "int": { + "value": "0" + }, + "float": { + "value": "1.25e-07" + }, + "lax_int": { + "error": "ValueError" + }, "json": "1.25e-07", "pickle": { "0": "46312e3235652d30370a2e", @@ -446,6 +653,15 @@ "repr": "5e-324", "str": "5e-324", "truthy": true, + "int": { + "value": "0" + }, + "float": { + "value": "5e-324" + }, + "lax_int": { + "error": "ValueError" + }, "json": "5e-324", "pickle": { "0": "4635652d3332340a2e", @@ -465,6 +681,15 @@ "repr": "1.7976931348623157e+308", "str": "1.7976931348623157e+308", "truthy": true, + "int": { + "value": "179769313486231570814527423731704356798070567525844996598917476803157260780028538760589558632766878171540458953514382464234321326889464182768467546703537516986049910576551282076245490090389328944075868508455133942304583236903222948165808559332123348274797826204144723168738177180919299881250404026184124858368" + }, + "float": { + "value": "1.7976931348623157e+308" + }, + "lax_int": { + "error": "ValueError" + }, "json": "1.7976931348623157e+308", "pickle": { "0": "46312e37393736393331333438363233313537652b3330380a2e", @@ -484,6 +709,15 @@ "repr": "1e+22", "str": "1e+22", "truthy": true, + "int": { + "value": "10000000000000000000000" + }, + "float": { + "value": "1e+22" + }, + "lax_int": { + "error": "ValueError" + }, "json": "1e+22", "pickle": { "0": "4631652b32320a2e", @@ -503,6 +737,15 @@ "repr": "inf", "str": "inf", "truthy": true, + "int": { + "error": "OverflowError" + }, + "float": { + "value": "inf" + }, + "lax_int": { + "error": "ValueError" + }, "json": "Infinity", "pickle": { "0": "46696e660a2e", @@ -522,6 +765,15 @@ "repr": "-inf", "str": "-inf", "truthy": true, + "int": { + "error": "OverflowError" + }, + "float": { + "value": "-inf" + }, + "lax_int": { + "error": "ValueError" + }, "json": "-Infinity", "pickle": { "0": "462d696e660a2e", @@ -541,6 +793,15 @@ "repr": "nan", "str": "nan", "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "value": "nan" + }, + "lax_int": { + "error": "ValueError" + }, "json": "NaN", "pickle": { "0": "466e616e0a2e", @@ -560,6 +821,15 @@ "repr": "1j", "str": "1j", "truthy": true, + "int": { + "error": "TypeError" + }, + "float": { + "error": "TypeError" + }, + "lax_int": { + "error": "ValueError" + }, "json_error": "Object of type complex is not JSON serializable", "pickle": { "0": "635f5f6275696c74696e5f5f0a636f6d706c65780a70300a2846302e300a46312e300a7470310a5270320a2e", @@ -579,6 +849,15 @@ "repr": "(-0-1j)", "str": "(-0-1j)", "truthy": true, + "int": { + "error": "TypeError" + }, + "float": { + "error": "TypeError" + }, + "lax_int": { + "error": "ValueError" + }, "json_error": "Object of type complex is not JSON serializable", "pickle": { "0": "635f5f6275696c74696e5f5f0a636f6d706c65780a70300a28462d302e300a462d312e300a7470310a5270320a2e", @@ -598,6 +877,15 @@ "repr": "-1j", "str": "-1j", "truthy": true, + "int": { + "error": "TypeError" + }, + "float": { + "error": "TypeError" + }, + "lax_int": { + "error": "ValueError" + }, "json_error": "Object of type complex is not JSON serializable", "pickle": { "0": "635f5f6275696c74696e5f5f0a636f6d706c65780a70300a2846302e300a462d312e300a7470310a5270320a2e", @@ -617,6 +905,15 @@ "repr": "(1+2j)", "str": "(1+2j)", "truthy": true, + "int": { + "error": "TypeError" + }, + "float": { + "error": "TypeError" + }, + "lax_int": { + "error": "ValueError" + }, "json_error": "Object of type complex is not JSON serializable", "pickle": { "0": "635f5f6275696c74696e5f5f0a636f6d706c65780a70300a2846312e300a46322e300a7470310a5270320a2e", @@ -636,6 +933,15 @@ "repr": "(-1.5-0.5j)", "str": "(-1.5-0.5j)", "truthy": true, + "int": { + "error": "TypeError" + }, + "float": { + "error": "TypeError" + }, + "lax_int": { + "error": "ValueError" + }, "json_error": "Object of type complex is not JSON serializable", "pickle": { "0": "635f5f6275696c74696e5f5f0a636f6d706c65780a70300a28462d312e350a462d302e350a7470310a5270320a2e", @@ -655,6 +961,15 @@ "repr": "1e+16j", "str": "1e+16j", "truthy": true, + "int": { + "error": "TypeError" + }, + "float": { + "error": "TypeError" + }, + "lax_int": { + "error": "ValueError" + }, "json_error": "Object of type complex is not JSON serializable", "pickle": { "0": "635f5f6275696c74696e5f5f0a636f6d706c65780a70300a2846302e300a4631652b31360a7470310a5270320a2e", @@ -674,6 +989,15 @@ "repr": "''", "str": "", "truthy": false, + "int": { + "error": "ValueError" + }, + "float": { + "error": "ValueError" + }, + "lax_int": { + "error": "ValueError" + }, "json": "\"\"", "pickle": { "0": "560a70300a2e", @@ -693,6 +1017,15 @@ "repr": "'plain'", "str": "plain", "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "error": "ValueError" + }, + "lax_int": { + "error": "ValueError" + }, "json": "\"plain\"", "pickle": { "0": "56706c61696e0a70300a2e", @@ -712,6 +1045,15 @@ "repr": "\"it's\"", "str": "it's", "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "error": "ValueError" + }, + "lax_int": { + "error": "ValueError" + }, "json": "\"it's\"", "pickle": { "0": "56697427730a70300a2e", @@ -731,6 +1073,15 @@ "repr": "'say \"hi\"'", "str": "say \"hi\"", "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "error": "ValueError" + }, + "lax_int": { + "error": "ValueError" + }, "json": "\"say \\\"hi\\\"\"", "pickle": { "0": "5673617920226869220a70300a2e", @@ -750,6 +1101,15 @@ "repr": "'both \\' and \"'", "str": "both ' and \"", "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "error": "ValueError" + }, + "lax_int": { + "error": "ValueError" + }, "json": "\"both ' and \\\"\"", "pickle": { "0": "56626f7468202720616e6420220a70300a2e", @@ -769,6 +1129,15 @@ "repr": "'back\\\\slash'", "str": "back\\slash", "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "error": "ValueError" + }, + "lax_int": { + "error": "ValueError" + }, "json": "\"back\\\\slash\"", "pickle": { "0": "566261636b5c7530303563736c6173680a70300a2e", @@ -788,6 +1157,15 @@ "repr": "'\\t\\n\\r'", "str": "\t\n\r", "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "error": "ValueError" + }, + "lax_int": { + "error": "ValueError" + }, "json": "\"\\t\\n\\r\"", "pickle": { "0": "56095c75303030615c75303030640a70300a2e", @@ -807,6 +1185,15 @@ "repr": "'\\x00\\x1f\\x7f'", "str": "\u0000\u001f\u007f", "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "error": "ValueError" + }, + "lax_int": { + "error": "ValueError" + }, "json": "\"\\u0000\\u001f\\u007f\"", "pickle": { "0": "565c75303030301f7f0a70300a2e", @@ -826,6 +1213,15 @@ "repr": "'\\x85\\xa0\\xad'", "str": "\u0085\u00a0\u00ad", "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "error": "ValueError" + }, + "lax_int": { + "error": "ValueError" + }, "json": "\"\\u0085\\u00a0\\u00ad\"", "pickle": { "0": "5685a0ad0a70300a2e", @@ -845,6 +1241,15 @@ "repr": "'caf\u00e9'", "str": "caf\u00e9", "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "error": "ValueError" + }, + "lax_int": { + "error": "ValueError" + }, "json": "\"caf\\u00e9\"", "pickle": { "0": "56636166e90a70300a2e", @@ -864,6 +1269,15 @@ "repr": "'\u65e5\u672c'", "str": "\u65e5\u672c", "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "error": "ValueError" + }, + "lax_int": { + "error": "ValueError" + }, "json": "\"\\u65e5\\u672c\"", "pickle": { "0": "565c75363565355c75363732630a70300a2e", @@ -883,6 +1297,15 @@ "repr": "'\\u200b\\u2028\\u3000'", "str": "\u200b\u2028\u3000", "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "error": "ValueError" + }, + "lax_int": { + "error": "ValueError" + }, "json": "\"\\u200b\\u2028\\u3000\"", "pickle": { "0": "565c75323030625c75323032385c75333030300a70300a2e", @@ -902,6 +1325,15 @@ "repr": "'\ud83d\ude00'", "str": "\ud83d\ude00", "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "error": "ValueError" + }, + "lax_int": { + "error": "ValueError" + }, "json": "\"\\ud83d\\ude00\"", "pickle": { "0": "565c5530303031663630300a70300a2e", @@ -921,6 +1353,15 @@ "repr": "'\\U000e0001\\U0010ffff'", "str": "\udb40\udc01\udbff\udfff", "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "error": "ValueError" + }, + "lax_int": { + "error": "ValueError" + }, "json": "\"\\udb40\\udc01\\udbff\\udfff\"", "pickle": { "0": "565c5530303065303030315c5530303130666666660a70300a2e", @@ -940,6 +1381,15 @@ "repr": "'\\x08\\x0c'", "str": "\b\f", "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "error": "ValueError" + }, + "lax_int": { + "error": "ValueError" + }, "json": "\"\\b\\f\"", "pickle": { "0": "56080c0a70300a2e", @@ -959,6 +1409,15 @@ "repr": "b''", "str": "b''", "truthy": false, + "int": { + "error": "ValueError" + }, + "float": { + "error": "ValueError" + }, + "lax_int": { + "error": "ValueError" + }, "json_error": "Object of type bytes is not JSON serializable", "pickle": { "0": "635f5f6275696c74696e5f5f0a62797465730a70300a28745270310a2e", @@ -978,6 +1437,15 @@ "repr": "b'abc'", "str": "b'abc'", "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "error": "ValueError" + }, + "lax_int": { + "error": "ValueError" + }, "json_error": "Object of type bytes is not JSON serializable", "pickle": { "0": "635f636f646563730a656e636f64650a70300a28566162630a70310a566c6174696e310a70320a7470330a5270340a2e", @@ -997,6 +1465,15 @@ "repr": "b\"a'b\"", "str": "b\"a'b\"", "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "error": "ValueError" + }, + "lax_int": { + "error": "ValueError" + }, "json_error": "Object of type bytes is not JSON serializable", "pickle": { "0": "635f636f646563730a656e636f64650a70300a28566127620a70310a566c6174696e310a70320a7470330a5270340a2e", @@ -1016,6 +1493,15 @@ "repr": "b'a\"b\\'c'", "str": "b'a\"b\\'c'", "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "error": "ValueError" + }, + "lax_int": { + "error": "ValueError" + }, "json_error": "Object of type bytes is not JSON serializable", "pickle": { "0": "635f636f646563730a656e636f64650a70300a285661226227630a70310a566c6174696e310a70320a7470330a5270340a2e", @@ -1035,6 +1521,15 @@ "repr": "b'\\x00\\t\\n\\r\\x7f\\x80\\xff'", "str": "b'\\x00\\t\\n\\r\\x7f\\x80\\xff'", "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "error": "ValueError" + }, + "lax_int": { + "error": "ValueError" + }, "json_error": "Object of type bytes is not JSON serializable", "pickle": { "0": "635f636f646563730a656e636f64650a70300a28565c7530303030095c75303030615c75303030647f80ff0a70310a566c6174696e310a70320a7470330a5270340a2e", @@ -1046,6 +1541,790 @@ }, "view": "b'\\x00\\t\\n\\r\\x7f\\x80\\xff'" }, + { + "name": "' 12 '", + "source": "' 12 '", + "literal": true, + "plain": true, + "repr": "' 12 '", + "str": " 12 ", + "truthy": true, + "int": { + "value": "12" + }, + "float": { + "value": "12.0" + }, + "lax_int": { + "value": "12" + }, + "json": "\" 12 \"", + "pickle": { + "0": "56203132200a70300a2e", + "1": "58040000002031322071002e", + "2": "800258040000002031322071002e", + "3": "800358040000002031322071002e", + "4": "80049508000000000000008c0420313220942e", + "5": "80059508000000000000008c0420313220942e" + }, + "view": "' 12 '" + }, + { + "name": "'+5'", + "source": "'+5'", + "literal": true, + "plain": true, + "repr": "'+5'", + "str": "+5", + "truthy": true, + "int": { + "value": "5" + }, + "float": { + "value": "5.0" + }, + "lax_int": { + "value": "5" + }, + "json": "\"+5\"", + "pickle": { + "0": "562b350a70300a2e", + "1": "58020000002b3571002e", + "2": "800258020000002b3571002e", + "3": "800358020000002b3571002e", + "4": "80049506000000000000008c022b35942e", + "5": "80059506000000000000008c022b35942e" + }, + "view": "'+5'" + }, + { + "name": "'-4'", + "source": "'-4'", + "literal": true, + "plain": true, + "repr": "'-4'", + "str": "-4", + "truthy": true, + "int": { + "value": "-4" + }, + "float": { + "value": "-4.0" + }, + "lax_int": { + "value": "-4" + }, + "json": "\"-4\"", + "pickle": { + "0": "562d340a70300a2e", + "1": "58020000002d3471002e", + "2": "800258020000002d3471002e", + "3": "800358020000002d3471002e", + "4": "80049506000000000000008c022d34942e", + "5": "80059506000000000000008c022d34942e" + }, + "view": "'-4'" + }, + { + "name": "'007'", + "source": "'007'", + "literal": true, + "plain": true, + "repr": "'007'", + "str": "007", + "truthy": true, + "int": { + "value": "7" + }, + "float": { + "value": "7.0" + }, + "lax_int": { + "value": "7" + }, + "json": "\"007\"", + "pickle": { + "0": "563030370a70300a2e", + "1": "580300000030303771002e", + "2": "8002580300000030303771002e", + "3": "8003580300000030303771002e", + "4": "80049507000000000000008c03303037942e", + "5": "80059507000000000000008c03303037942e" + }, + "view": "'007'" + }, + { + "name": "'1_000'", + "source": "'1_000'", + "literal": true, + "plain": true, + "repr": "'1_000'", + "str": "1_000", + "truthy": true, + "int": { + "value": "1000" + }, + "float": { + "value": "1000.0" + }, + "lax_int": { + "value": "1000" + }, + "json": "\"1_000\"", + "pickle": { + "0": "56315f3030300a70300a2e", + "1": "5805000000315f30303071002e", + "2": "80025805000000315f30303071002e", + "3": "80035805000000315f30303071002e", + "4": "80049509000000000000008c05315f303030942e", + "5": "80059509000000000000008c05315f303030942e" + }, + "view": "'1_000'" + }, + { + "name": "'1__0'", + "source": "'1__0'", + "literal": true, + "plain": true, + "repr": "'1__0'", + "str": "1__0", + "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "error": "ValueError" + }, + "lax_int": { + "error": "ValueError" + }, + "json": "\"1__0\"", + "pickle": { + "0": "56315f5f300a70300a2e", + "1": "5804000000315f5f3071002e", + "2": "80025804000000315f5f3071002e", + "3": "80035804000000315f5f3071002e", + "4": "80049508000000000000008c04315f5f30942e", + "5": "80059508000000000000008c04315f5f30942e" + }, + "view": "'1__0'" + }, + { + "name": "'_1'", + "source": "'_1'", + "literal": true, + "plain": true, + "repr": "'_1'", + "str": "_1", + "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "error": "ValueError" + }, + "lax_int": { + "error": "ValueError" + }, + "json": "\"_1\"", + "pickle": { + "0": "565f310a70300a2e", + "1": "58020000005f3171002e", + "2": "800258020000005f3171002e", + "3": "800358020000005f3171002e", + "4": "80049506000000000000008c025f31942e", + "5": "80059506000000000000008c025f31942e" + }, + "view": "'_1'" + }, + { + "name": "'1_'", + "source": "'1_'", + "literal": true, + "plain": true, + "repr": "'1_'", + "str": "1_", + "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "error": "ValueError" + }, + "lax_int": { + "error": "ValueError" + }, + "json": "\"1_\"", + "pickle": { + "0": "56315f0a70300a2e", + "1": "5802000000315f71002e", + "2": "80025802000000315f71002e", + "3": "80035802000000315f71002e", + "4": "80049506000000000000008c02315f942e", + "5": "80059506000000000000008c02315f942e" + }, + "view": "'1_'" + }, + { + "name": "'3.0'", + "source": "'3.0'", + "literal": true, + "plain": true, + "repr": "'3.0'", + "str": "3.0", + "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "value": "3.0" + }, + "lax_int": { + "value": "3" + }, + "json": "\"3.0\"", + "pickle": { + "0": "56332e300a70300a2e", + "1": "5803000000332e3071002e", + "2": "80025803000000332e3071002e", + "3": "80035803000000332e3071002e", + "4": "80049507000000000000008c03332e30942e", + "5": "80059507000000000000008c03332e30942e" + }, + "view": "'3.0'" + }, + { + "name": "'3.00'", + "source": "'3.00'", + "literal": true, + "plain": true, + "repr": "'3.00'", + "str": "3.00", + "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "value": "3.0" + }, + "lax_int": { + "value": "3" + }, + "json": "\"3.00\"", + "pickle": { + "0": "56332e30300a70300a2e", + "1": "5804000000332e303071002e", + "2": "80025804000000332e303071002e", + "3": "80035804000000332e303071002e", + "4": "80049508000000000000008c04332e3030942e", + "5": "80059508000000000000008c04332e3030942e" + }, + "view": "'3.00'" + }, + { + "name": "'3.5'", + "source": "'3.5'", + "literal": true, + "plain": true, + "repr": "'3.5'", + "str": "3.5", + "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "value": "3.5" + }, + "lax_int": { + "error": "ValueError" + }, + "json": "\"3.5\"", + "pickle": { + "0": "56332e350a70300a2e", + "1": "5803000000332e3571002e", + "2": "80025803000000332e3571002e", + "3": "80035803000000332e3571002e", + "4": "80049507000000000000008c03332e35942e", + "5": "80059507000000000000008c03332e35942e" + }, + "view": "'3.5'" + }, + { + "name": "' 0.5 '", + "source": "' 0.5 '", + "literal": true, + "plain": true, + "repr": "' 0.5 '", + "str": " 0.5 ", + "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "value": "0.5" + }, + "lax_int": { + "error": "ValueError" + }, + "json": "\" 0.5 \"", + "pickle": { + "0": "5620302e35200a70300a2e", + "1": "580500000020302e352071002e", + "2": "8002580500000020302e352071002e", + "3": "8003580500000020302e352071002e", + "4": "80049509000000000000008c0520302e3520942e", + "5": "80059509000000000000008c0520302e3520942e" + }, + "view": "' 0.5 '" + }, + { + "name": "'.5'", + "source": "'.5'", + "literal": true, + "plain": true, + "repr": "'.5'", + "str": ".5", + "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "value": "0.5" + }, + "lax_int": { + "error": "ValueError" + }, + "json": "\".5\"", + "pickle": { + "0": "562e350a70300a2e", + "1": "58020000002e3571002e", + "2": "800258020000002e3571002e", + "3": "800358020000002e3571002e", + "4": "80049506000000000000008c022e35942e", + "5": "80059506000000000000008c022e35942e" + }, + "view": "'.5'" + }, + { + "name": "'5.'", + "source": "'5.'", + "literal": true, + "plain": true, + "repr": "'5.'", + "str": "5.", + "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "value": "5.0" + }, + "lax_int": { + "error": "ValueError" + }, + "json": "\"5.\"", + "pickle": { + "0": "56352e0a70300a2e", + "1": "5802000000352e71002e", + "2": "80025802000000352e71002e", + "3": "80035802000000352e71002e", + "4": "80049506000000000000008c02352e942e", + "5": "80059506000000000000008c02352e942e" + }, + "view": "'5.'" + }, + { + "name": "'1e3'", + "source": "'1e3'", + "literal": true, + "plain": true, + "repr": "'1e3'", + "str": "1e3", + "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "value": "1000.0" + }, + "lax_int": { + "error": "ValueError" + }, + "json": "\"1e3\"", + "pickle": { + "0": "563165330a70300a2e", + "1": "580300000031653371002e", + "2": "8002580300000031653371002e", + "3": "8003580300000031653371002e", + "4": "80049507000000000000008c03316533942e", + "5": "80059507000000000000008c03316533942e" + }, + "view": "'1e3'" + }, + { + "name": "'1_0.5'", + "source": "'1_0.5'", + "literal": true, + "plain": true, + "repr": "'1_0.5'", + "str": "1_0.5", + "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "value": "10.5" + }, + "lax_int": { + "error": "ValueError" + }, + "json": "\"1_0.5\"", + "pickle": { + "0": "56315f302e350a70300a2e", + "1": "5805000000315f302e3571002e", + "2": "80025805000000315f302e3571002e", + "3": "80035805000000315f302e3571002e", + "4": "80049509000000000000008c05315f302e35942e", + "5": "80059509000000000000008c05315f302e35942e" + }, + "view": "'1_0.5'" + }, + { + "name": "'1e1_0'", + "source": "'1e1_0'", + "literal": true, + "plain": true, + "repr": "'1e1_0'", + "str": "1e1_0", + "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "value": "10000000000.0" + }, + "lax_int": { + "error": "ValueError" + }, + "json": "\"1e1_0\"", + "pickle": { + "0": "563165315f300a70300a2e", + "1": "58050000003165315f3071002e", + "2": "800258050000003165315f3071002e", + "3": "800358050000003165315f3071002e", + "4": "80049509000000000000008c053165315f30942e", + "5": "80059509000000000000008c053165315f30942e" + }, + "view": "'1e1_0'" + }, + { + "name": "'inf'", + "source": "'inf'", + "literal": true, + "plain": true, + "repr": "'inf'", + "str": "inf", + "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "value": "inf" + }, + "lax_int": { + "error": "ValueError" + }, + "json": "\"inf\"", + "pickle": { + "0": "56696e660a70300a2e", + "1": "5803000000696e6671002e", + "2": "80025803000000696e6671002e", + "3": "80035803000000696e6671002e", + "4": "80049507000000000000008c03696e66942e", + "5": "80059507000000000000008c03696e66942e" + }, + "view": "'inf'" + }, + { + "name": "'-Infinity'", + "source": "'-Infinity'", + "literal": true, + "plain": true, + "repr": "'-Infinity'", + "str": "-Infinity", + "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "value": "-inf" + }, + "lax_int": { + "error": "ValueError" + }, + "json": "\"-Infinity\"", + "pickle": { + "0": "562d496e66696e6974790a70300a2e", + "1": "58090000002d496e66696e69747971002e", + "2": "800258090000002d496e66696e69747971002e", + "3": "800358090000002d496e66696e69747971002e", + "4": "8004950d000000000000008c092d496e66696e697479942e", + "5": "8005950d000000000000008c092d496e66696e697479942e" + }, + "view": "'-Infinity'" + }, + { + "name": "'nan'", + "source": "'nan'", + "literal": true, + "plain": true, + "repr": "'nan'", + "str": "nan", + "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "value": "nan" + }, + "lax_int": { + "error": "ValueError" + }, + "json": "\"nan\"", + "pickle": { + "0": "566e616e0a70300a2e", + "1": "58030000006e616e71002e", + "2": "800258030000006e616e71002e", + "3": "800358030000006e616e71002e", + "4": "80049507000000000000008c036e616e942e", + "5": "80059507000000000000008c036e616e942e" + }, + "view": "'nan'" + }, + { + "name": "'NaN'", + "source": "'NaN'", + "literal": true, + "plain": true, + "repr": "'NaN'", + "str": "NaN", + "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "value": "nan" + }, + "lax_int": { + "error": "ValueError" + }, + "json": "\"NaN\"", + "pickle": { + "0": "564e614e0a70300a2e", + "1": "58030000004e614e71002e", + "2": "800258030000004e614e71002e", + "3": "800358030000004e614e71002e", + "4": "80049507000000000000008c034e614e942e", + "5": "80059507000000000000008c034e614e942e" + }, + "view": "'NaN'" + }, + { + "name": "'0x10'", + "source": "'0x10'", + "literal": true, + "plain": true, + "repr": "'0x10'", + "str": "0x10", + "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "error": "ValueError" + }, + "lax_int": { + "error": "ValueError" + }, + "json": "\"0x10\"", + "pickle": { + "0": "56307831300a70300a2e", + "1": "58040000003078313071002e", + "2": "800258040000003078313071002e", + "3": "800358040000003078313071002e", + "4": "80049508000000000000008c0430783130942e", + "5": "80059508000000000000008c0430783130942e" + }, + "view": "'0x10'" + }, + { + "name": "'abc'", + "source": "'abc'", + "literal": true, + "plain": true, + "repr": "'abc'", + "str": "abc", + "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "error": "ValueError" + }, + "lax_int": { + "error": "ValueError" + }, + "json": "\"abc\"", + "pickle": { + "0": "566162630a70300a2e", + "1": "580300000061626371002e", + "2": "8002580300000061626371002e", + "3": "8003580300000061626371002e", + "4": "80049507000000000000008c03616263942e", + "5": "80059507000000000000008c03616263942e" + }, + "view": "'abc'" + }, + { + "name": "b'12'", + "source": "b'12'", + "literal": true, + "plain": true, + "repr": "b'12'", + "str": "b'12'", + "truthy": true, + "int": { + "value": "12" + }, + "float": { + "value": "12.0" + }, + "lax_int": { + "value": "12" + }, + "json_error": "Object of type bytes is not JSON serializable", + "pickle": { + "0": "635f636f646563730a656e636f64650a70300a285631320a70310a566c6174696e310a70320a7470330a5270340a2e", + "1": "635f636f646563730a656e636f64650a71002858020000003132710158060000006c6174696e3171027471035271042e", + "2": "8002635f636f646563730a656e636f64650a710058020000003132710158060000006c6174696e3171028671035271042e", + "3": "80034302313271002e", + "4": "800495060000000000000043023132942e", + "5": "800595060000000000000043023132942e" + }, + "view": "b'12'" + }, + { + "name": "b' 1.5 '", + "source": "b' 1.5 '", + "literal": true, + "plain": true, + "repr": "b' 1.5 '", + "str": "b' 1.5 '", + "truthy": true, + "int": { + "error": "ValueError" + }, + "float": { + "value": "1.5" + }, + "lax_int": { + "error": "ValueError" + }, + "json_error": "Object of type bytes is not JSON serializable", + "pickle": { + "0": "635f636f646563730a656e636f64650a70300a285620312e35200a70310a566c6174696e310a70320a7470330a5270340a2e", + "1": "635f636f646563730a656e636f64650a710028580500000020312e3520710158060000006c6174696e3171027471035271042e", + "2": "8002635f636f646563730a656e636f64650a7100580500000020312e3520710158060000006c6174696e3171028671035271042e", + "3": "8003430520312e352071002e", + "4": "8004950900000000000000430520312e3520942e", + "5": "8005950900000000000000430520312e3520942e" + }, + "view": "b' 1.5 '" + }, + { + "name": "3.9", + "source": "3.9", + "literal": true, + "plain": true, + "repr": "3.9", + "str": "3.9", + "truthy": true, + "int": { + "value": "3" + }, + "float": { + "value": "3.9" + }, + "lax_int": { + "error": "ValueError" + }, + "json": "3.9", + "pickle": { + "0": "46332e390a2e", + "1": "47400f3333333333332e", + "2": "800247400f3333333333332e", + "3": "800347400f3333333333332e", + "4": "8004950a0000000000000047400f3333333333332e", + "5": "8005950a0000000000000047400f3333333333332e" + }, + "view": "3.9" + }, + { + "name": "-3.9", + "source": "-3.9", + "literal": true, + "plain": true, + "repr": "-3.9", + "str": "-3.9", + "truthy": true, + "int": { + "value": "-3" + }, + "float": { + "value": "-3.9" + }, + "lax_int": { + "error": "ValueError" + }, + "json": "-3.9", + "pickle": { + "0": "462d332e390a2e", + "1": "47c00f3333333333332e", + "2": "800247c00f3333333333332e", + "3": "800347c00f3333333333332e", + "4": "8004950a0000000000000047c00f3333333333332e", + "5": "8005950a0000000000000047c00f3333333333332e" + }, + "view": "-3.9" + }, + { + "name": "2.5", + "source": "2.5", + "literal": true, + "plain": true, + "repr": "2.5", + "str": "2.5", + "truthy": true, + "int": { + "value": "2" + }, + "float": { + "value": "2.5" + }, + "lax_int": { + "error": "ValueError" + }, + "json": "2.5", + "pickle": { + "0": "46322e350a2e", + "1": "4740040000000000002e", + "2": "80024740040000000000002e", + "3": "80034740040000000000002e", + "4": "8004950a000000000000004740040000000000002e", + "5": "8005950a000000000000004740040000000000002e" + }, + "view": "2.5" + }, { "name": "[]", "source": "[]", @@ -1054,6 +2333,15 @@ "repr": "[]", "str": "[]", "truthy": false, + "int": { + "error": "TypeError" + }, + "float": { + "error": "TypeError" + }, + "lax_int": { + "error": "ValueError" + }, "json": "[]", "pickle": { "0": "286c70300a2e", @@ -1073,6 +2361,15 @@ "repr": "[1, 'a', None, True]", "str": "[1, 'a', None, True]", "truthy": true, + "int": { + "error": "TypeError" + }, + "float": { + "error": "TypeError" + }, + "lax_int": { + "error": "ValueError" + }, "json": "[1, \"a\", null, true]", "pickle": { "0": "286c70300a49310a6156610a70310a614e614930310a612e", @@ -1092,6 +2389,15 @@ "repr": "()", "str": "()", "truthy": false, + "int": { + "error": "TypeError" + }, + "float": { + "error": "TypeError" + }, + "lax_int": { + "error": "ValueError" + }, "json": "[]", "pickle": { "0": "28742e", @@ -1111,6 +2417,15 @@ "repr": "(1,)", "str": "(1,)", "truthy": true, + "int": { + "error": "TypeError" + }, + "float": { + "error": "TypeError" + }, + "lax_int": { + "error": "ValueError" + }, "json": "[1]", "pickle": { "0": "2849310a7470300a2e", @@ -1130,6 +2445,15 @@ "repr": "(1, (2, 3))", "str": "(1, (2, 3))", "truthy": true, + "int": { + "error": "TypeError" + }, + "float": { + "error": "TypeError" + }, + "lax_int": { + "error": "ValueError" + }, "json": "[1, [2, 3]]", "pickle": { "0": "2849310a2849320a49330a7470300a7470310a2e", @@ -1149,6 +2473,15 @@ "repr": "{}", "str": "{}", "truthy": false, + "int": { + "error": "TypeError" + }, + "float": { + "error": "TypeError" + }, + "lax_int": { + "error": "ValueError" + }, "json": "{}", "pickle": { "0": "286470300a2e", @@ -1168,6 +2501,15 @@ "repr": "{'a': 1, 'b': [1.0, 2.5]}", "str": "{'a': 1, 'b': [1.0, 2.5]}", "truthy": true, + "int": { + "error": "TypeError" + }, + "float": { + "error": "TypeError" + }, + "lax_int": { + "error": "ValueError" + }, "json": "{\"a\": 1, \"b\": [1.0, 2.5]}", "pickle": { "0": "286470300a56610a70310a49310a7356620a70320a286c70330a46312e300a6146322e350a61732e", @@ -1187,6 +2529,15 @@ "repr": "{'z': 1, 'a': 2, 'm': 3}", "str": "{'z': 1, 'a': 2, 'm': 3}", "truthy": true, + "int": { + "error": "TypeError" + }, + "float": { + "error": "TypeError" + }, + "lax_int": { + "error": "ValueError" + }, "json": "{\"z\": 1, \"a\": 2, \"m\": 3}", "pickle": { "0": "286470300a567a0a70310a49310a7356610a70320a49320a73566d0a70330a49330a732e", @@ -1206,6 +2557,15 @@ "repr": "{1: 'bool', 2.5: 'float', None: 'none'}", "str": "{1: 'bool', 2.5: 'float', None: 'none'}", "truthy": true, + "int": { + "error": "TypeError" + }, + "float": { + "error": "TypeError" + }, + "lax_int": { + "error": "ValueError" + }, "json": "{\"1\": \"bool\", \"2.5\": \"float\", \"null\": \"none\"}", "pickle": { "0": "286470300a49310a56626f6f6c0a70310a7346322e350a56666c6f61740a70320a734e566e6f6e650a70330a732e", @@ -1225,6 +2585,15 @@ "repr": "{(1, 2): 'tuple key'}", "str": "{(1, 2): 'tuple key'}", "truthy": true, + "int": { + "error": "TypeError" + }, + "float": { + "error": "TypeError" + }, + "lax_int": { + "error": "ValueError" + }, "json_error": "keys must be str, int, float, bool or None, not tuple", "pickle": { "0": "286470300a2849310a49320a7470310a567475706c65206b65790a70320a732e", @@ -1244,6 +2613,15 @@ "repr": "{'nested': {'deeper': {'deepest': [{}]}}}", "str": "{'nested': {'deeper': {'deepest': [{}]}}}", "truthy": true, + "int": { + "error": "TypeError" + }, + "float": { + "error": "TypeError" + }, + "lax_int": { + "error": "ValueError" + }, "json": "{\"nested\": {\"deeper\": {\"deepest\": [{}]}}}", "pickle": { "0": "286470300a566e65737465640a70310a286470320a566465657065720a70330a286470340a56646565706573740a70350a286c70360a286470370a617373732e", @@ -1263,6 +2641,15 @@ "repr": "{1}", "str": "{1}", "truthy": true, + "int": { + "error": "TypeError" + }, + "float": { + "error": "TypeError" + }, + "lax_int": { + "error": "ValueError" + }, "json_error": "Object of type set is not JSON serializable", "pickle": { "0": "635f5f6275696c74696e5f5f0a7365740a70300a28286c70310a49310a617470320a5270330a2e", @@ -1282,6 +2669,15 @@ "repr": "set()", "str": "set()", "truthy": false, + "int": { + "error": "TypeError" + }, + "float": { + "error": "TypeError" + }, + "lax_int": { + "error": "ValueError" + }, "json_error": "Object of type set is not JSON serializable", "pickle": { "0": "635f5f6275696c74696e5f5f0a7365740a70300a28286c70310a7470320a5270330a2e", @@ -1301,6 +2697,15 @@ "repr": "frozenset({1})", "str": "frozenset({1})", "truthy": true, + "int": { + "error": "TypeError" + }, + "float": { + "error": "TypeError" + }, + "lax_int": { + "error": "ValueError" + }, "json_error": "Object of type frozenset is not JSON serializable", "pickle": { "0": "635f5f6275696c74696e5f5f0a66726f7a656e7365740a70300a28286c70310a49310a617470320a5270330a2e", @@ -1320,6 +2725,15 @@ "repr": "[[[[[[[[[[1]]]]]]]]]]", "str": "[[[[[[[[[[1]]]]]]]]]]", "truthy": true, + "int": { + "error": "TypeError" + }, + "float": { + "error": "TypeError" + }, + "lax_int": { + "error": "ValueError" + }, "json": "[[[[[[[[[[1]]]]]]]]]]", "pickle": { "0": "286c70300a286c70310a286c70320a286c70330a286c70340a286c70350a286c70360a286c70370a286c70380a286c70390a49310a616161616161616161612e", @@ -1339,6 +2753,15 @@ "repr": "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[1]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]", "str": "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[1]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]", "truthy": true, + "int": { + "error": "TypeError" + }, + "float": { + "error": "TypeError" + }, + "lax_int": { + "error": "ValueError" + }, "json": "[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[[1]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]]", "pickle": { "0": "286c70300a286c70310a286c70320a286c70330a286c70340a286c70350a286c70360a286c70370a286c70380a286c70390a286c7031300a286c7031310a286c7031320a286c7031330a286c7031340a286c7031350a286c7031360a286c7031370a286c7031380a286c7031390a286c7032300a286c7032310a286c7032320a286c7032330a286c7032340a286c7032350a286c7032360a286c7032370a286c7032380a286c7032390a286c7033300a286c7033310a286c7033320a286c7033330a286c7033340a286c7033350a286c7033360a286c7033370a286c7033380a286c7033390a286c7034300a286c7034310a286c7034320a286c7034330a286c7034340a286c7034350a286c7034360a286c7034370a286c7034380a286c7034390a286c7035300a286c7035310a286c7035320a286c7035330a286c7035340a286c7035350a286c7035360a286c7035370a286c7035380a286c7035390a286c7036300a286c7036310a286c7036320a286c7036330a286c7036340a286c7036350a286c7036360a286c7036370a286c7036380a286c7036390a286c7037300a286c7037310a286c7037320a286c7037330a286c7037340a286c7037350a286c7037360a286c7037370a286c7037380a286c7037390a286c7038300a286c7038310a286c7038320a286c7038330a286c7038340a286c7038350a286c7038360a286c7038370a286c7038380a286c7038390a286c7039300a286c7039310a286c7039320a286c7039330a286c7039340a286c7039350a286c7039360a286c7039370a286c7039380a286c7039390a286c703130300a286c703130310a286c703130320a286c703130330a286c703130340a286c703130350a286c703130360a286c703130370a286c703130380a286c703130390a286c703131300a286c703131310a286c703131320a286c703131330a286c703131340a286c703131350a286c703131360a286c703131370a286c703131380a286c703131390a286c703132300a286c703132310a286c703132320a286c703132330a286c703132340a286c703132350a286c703132360a286c703132370a286c703132380a286c703132390a286c703133300a286c703133310a286c703133320a286c703133330a286c703133340a286c703133350a286c703133360a286c703133370a286c703133380a286c703133390a286c703134300a286c703134310a286c703134320a286c703134330a286c703134340a286c703134350a286c703134360a286c703134370a286c703134380a286c703134390a49310a6161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161616161612e", @@ -1358,6 +2781,15 @@ "repr": "{'timestamp': 1726000000.123, 'response': '{\"id\": \"chatcmpl-1\", \"object\": \"chat.completion\"}'}", "str": "{'timestamp': 1726000000.123, 'response': '{\"id\": \"chatcmpl-1\", \"object\": \"chat.completion\"}'}", "truthy": true, + "int": { + "error": "TypeError" + }, + "float": { + "error": "TypeError" + }, + "lax_int": { + "error": "ValueError" + }, "json": "{\"timestamp\": 1726000000.123, \"response\": \"{\\\"id\\\": \\\"chatcmpl-1\\\", \\\"object\\\": \\\"chat.completion\\\"}\"}", "pickle": { "0": "286470300a5674696d657374616d700a70310a46313732363030303030302e3132330a7356726573706f6e73650a70320a567b226964223a202263686174636d706c2d31222c20226f626a656374223a2022636861742e636f6d706c6574696f6e227d0a70330a732e", @@ -1377,6 +2809,15 @@ "repr": "{'model': 'gpt-4o', 'messages': [{'role': 'user', 'content': 'hi'}], 'temperature': 0.2, 'stream': False}", "str": "{'model': 'gpt-4o', 'messages': [{'role': 'user', 'content': 'hi'}], 'temperature': 0.2, 'stream': False}", "truthy": true, + "int": { + "error": "TypeError" + }, + "float": { + "error": "TypeError" + }, + "lax_int": { + "error": "ValueError" + }, "json": "{\"model\": \"gpt-4o\", \"messages\": [{\"role\": \"user\", \"content\": \"hi\"}], \"temperature\": 0.2, \"stream\": false}", "pickle": { "0": "286470300a566d6f64656c0a70310a566770742d346f0a70320a73566d657373616765730a70330a286c70340a286470350a56726f6c650a70360a56757365720a70370a7356636f6e74656e740a70380a5668690a70390a7361735674656d70657261747572650a7031300a46302e320a735673747265616d0a7031310a4930300a732e", diff --git a/litellm-rust/crates/python-compat/scripts/generate_fixtures.py b/litellm-rust/crates/python-compat/scripts/generate_fixtures.py index 26456a638f6..32b198eef8d 100644 --- a/litellm-rust/crates/python-compat/scripts/generate_fixtures.py +++ b/litellm-rust/crates/python-compat/scripts/generate_fixtures.py @@ -2,8 +2,9 @@ python scripts/generate_fixtures.py > generated/values.json -Each row records `repr`, `str`, `json.dumps` (or its error), `bool`, and `pickle.dumps` at -every protocol. `literal` says whether `ast.literal_eval(repr(value))` gives the value back, +Each row records `repr`, `str`, `json.dumps` (or its error), `bool`, `int`, `float`, pydantic's +lax `int` validation, and `pickle.dumps` at every protocol. Conversions record the result's +`repr` or the exception class raised. Run it with the repository environment, which has pydantic. `literal` says whether `ast.literal_eval(repr(value))` gives the value back, which is how Python reads `str(dict)` text back from a cache; the Rust tests reach the other rows only through pickle. `view` is `repr` of the value as `pickle::loads` decodes it, with tuples, sets, and frozensets rendered as lists. `sources` records `ast.literal_eval` on raw @@ -16,6 +17,10 @@ import pickle import sys import warnings +from pydantic import TypeAdapter, ValidationError + +LAX_INT = TypeAdapter(int) + # Entries are source texts, or `(name, source)` when the source is too long to read in a # test report. `name` is what the Rust `KNOWN` table keys on. CORPUS = [ @@ -79,6 +84,35 @@ CORPUS = [ 'b"a\'b"', "b'a\"b\\'c'", "b'\\x00\\t\\n\\r\\x7f\\x80\\xff'", + # Numeric text, as providers and config files send it + "' 12 '", + "'+5'", + "'-4'", + "'007'", + "'1_000'", + "'1__0'", + "'_1'", + "'1_'", + "'3.0'", + "'3.00'", + "'3.5'", + "' 0.5 '", + "'.5'", + "'5.'", + "'1e3'", + "'1_0.5'", + "'1e1_0'", + "'inf'", + "'-Infinity'", + "'nan'", + "'NaN'", + "'0x10'", + "'abc'", + "b'12'", + "b' 1.5 '", + "3.9", + "-3.9", + "2.5", # Containers "[]", "[1, 'a', None, True]", @@ -314,6 +348,13 @@ def is_literal(value): return repr(parsed) == repr(value) +def converted(convert, value): + try: + return {"value": repr(convert(value))} + except (TypeError, ValueError, OverflowError, ValidationError) as error: + return {"error": "ValueError" if isinstance(error, ValidationError) else type(error).__name__} + + def row(entry): name, source = named(entry) value = eval(source) @@ -325,6 +366,9 @@ def row(entry): "repr": repr(value), "str": str(value), "truthy": bool(value), + "int": converted(int, value), + "float": converted(float, value), + "lax_int": converted(LAX_INT.validate_python, value), } try: entry["json"] = json.dumps(value) diff --git a/litellm-rust/crates/python-compat/src/error.rs b/litellm-rust/crates/python-compat/src/error.rs index 43990eb7602..088215f3bf3 100644 --- a/litellm-rust/crates/python-compat/src/error.rs +++ b/litellm-rust/crates/python-compat/src/error.rs @@ -1,5 +1,13 @@ use crate::MAX_DEPTH; +/// The CPython exception class a failed conversion raises. +#[derive(Clone, Copy, Debug, Eq, PartialEq, strum::Display, strum::IntoStaticStr)] +pub enum PythonException { + TypeError, + ValueError, + OverflowError, +} + /// A failure to read or write a Python format. Messages quote CPython's own wording where /// the Python side raises (`TypeError`, `ValueError`), so callers can log them as is. #[derive(Debug, thiserror::Error)] @@ -22,4 +30,18 @@ pub enum Error { IntegerOutOfRange, #[error("Object of type {0} cannot be pickled as plain data")] NotPicklable(&'static str), + #[error("{exception}: {message}")] + Conversion { + exception: PythonException, + message: String, + }, +} + +impl Error { + pub(crate) fn conversion(exception: PythonException, message: impl Into) -> Self { + Self::Conversion { + exception, + message: message.into(), + } + } } diff --git a/litellm-rust/crates/python-compat/src/lib.rs b/litellm-rust/crates/python-compat/src/lib.rs index b23aff409f2..0ef98b29aca 100644 --- a/litellm-rust/crates/python-compat/src/lib.rs +++ b/litellm-rust/crates/python-compat/src/lib.rs @@ -10,6 +10,8 @@ //! | [`json`] | `json.dumps(value)`, and `json.loads(json.dumps(value))` as a JSON value | //! | [`pickle`] | `pickle.loads(data)` and `pickle.dumps(value)` for plain data | //! | [`truthy`] | `bool(value)` | +//! | [`number`] | `int(value)` and `float(value)` | +//! | [`pydantic`] | pydantic's lax-mode `int` validation | //! //! [`Value`] is the closed data model these formats share. Live Python objects //! (descriptors, `__bool__`, `__str__`, callbacks) are out of scope: those belong to the @@ -24,12 +26,14 @@ mod error; pub mod json; pub mod literal; +pub mod number; pub mod pickle; +pub mod pydantic; pub mod repr; pub mod truthy; mod value; -pub use error::Error; +pub use error::{Error, PythonException}; pub use num_bigint::BigInt; pub use value::Value; diff --git a/litellm-rust/crates/python-compat/src/number.rs b/litellm-rust/crates/python-compat/src/number.rs new file mode 100644 index 00000000000..661ed54ef5b --- /dev/null +++ b/litellm-rust/crates/python-compat/src/number.rs @@ -0,0 +1,118 @@ +//! `int(value)` and `float(value)` for plain data. + +use num_bigint::BigInt; +use num_traits::{FromPrimitive, ToPrimitive}; + +use crate::repr::repr; +use crate::{Error, PythonException, Value}; + +/// Digits with single underscores between them, as Python's numeric literals allow. +pub(crate) fn without_digit_separators(text: &str) -> Option { + let bytes = text.as_bytes(); + let separators_ok = bytes.iter().enumerate().all(|(index, byte)| { + *byte != b'_' + || (index > 0 + && bytes[index - 1].is_ascii_digit() + && bytes.get(index + 1).is_some_and(u8::is_ascii_digit)) + }); + separators_ok.then(|| text.replace('_', "")) +} + +pub(crate) fn parse_int_literal(text: &str) -> Option { + let trimmed = text.trim(); + let digits = trimmed.strip_prefix(['+', '-']).unwrap_or(trimmed); + if digits.is_empty() + || !digits + .bytes() + .all(|byte| byte.is_ascii_digit() || byte == b'_') + { + return None; + } + without_digit_separators(trimmed)?.parse().ok() +} + +fn int_from_text(text: &str, shown: &Value) -> Result { + parse_int_literal(text).ok_or_else(|| { + Error::conversion( + PythonException::ValueError, + format!("invalid literal for int() with base 10: {}", repr(shown)), + ) + }) +} + +pub(crate) fn int_from_float(value: f64) -> Result { + if value.is_nan() { + return Err(Error::conversion( + PythonException::ValueError, + "cannot convert float NaN to integer", + )); + } + BigInt::from_f64(value.trunc()).ok_or_else(|| { + Error::conversion( + PythonException::OverflowError, + "cannot convert float infinity to integer", + ) + }) +} + +/// `int(value)`. +pub fn int(value: &Value) -> Result { + match value { + Value::Bool(flag) => Ok(BigInt::from(u8::from(*flag))), + Value::Int(number) => Ok(number.clone()), + Value::Float(number) => int_from_float(*number), + Value::Str(text) => int_from_text(text, value), + Value::Bytes(bytes) => int_from_text(&String::from_utf8_lossy(bytes), value), + other => Err(Error::conversion( + PythonException::TypeError, + format!( + "int() argument must be a string, a bytes-like object or a real number, not '{}'", + other.type_name() + ), + )), + } +} + +fn float_from_text(text: &str, shown: &Value) -> Result { + let trimmed = text.trim(); + let well_formed = !trimmed.is_empty() + && trimmed + .bytes() + .all(|byte| byte.is_ascii_alphanumeric() || matches!(byte, b'.' | b'_' | b'+' | b'-')); + well_formed + .then(|| without_digit_separators(trimmed)) + .flatten() + .and_then(|number| number.parse().ok()) + .ok_or_else(|| { + Error::conversion( + PythonException::ValueError, + format!("could not convert string to float: {}", repr(shown)), + ) + }) +} + +/// `float(value)`. +pub fn float(value: &Value) -> Result { + match value { + Value::Bool(flag) => Ok(f64::from(u8::from(*flag))), + Value::Int(number) => number + .to_f64() + .filter(|float| float.is_finite()) + .ok_or_else(|| { + Error::conversion( + PythonException::OverflowError, + "int too large to convert to float", + ) + }), + Value::Float(number) => Ok(*number), + Value::Str(text) => float_from_text(text, value), + Value::Bytes(bytes) => float_from_text(&String::from_utf8_lossy(bytes), value), + other => Err(Error::conversion( + PythonException::TypeError, + format!( + "float() argument must be a string or a real number, not '{}'", + other.type_name() + ), + )), + } +} diff --git a/litellm-rust/crates/python-compat/src/pydantic.rs b/litellm-rust/crates/python-compat/src/pydantic.rs new file mode 100644 index 00000000000..fe3c37c1042 --- /dev/null +++ b/litellm-rust/crates/python-compat/src/pydantic.rs @@ -0,0 +1,54 @@ +//! pydantic's lax-mode validation, which LiteLLM's usage and response models apply to the +//! numbers providers send. + +use num_bigint::BigInt; +use num_traits::Zero; + +use crate::number::{int_from_float, parse_int_literal}; +use crate::{Error, PythonException, Value}; + +/// pydantic-core converts floats through `i64`, so larger magnitudes fail validation. +const I64_LIMIT: f64 = 9_223_372_036_854_775_808.0; + +/// pydantic raises `ValidationError`, a `ValueError` subclass, for every rejected input. +fn invalid(message: &str) -> Error { + Error::conversion(PythonException::ValueError, message) +} + +fn int_from_text(text: &str) -> Result { + let trimmed = text.trim(); + let without_zero_fraction = trimmed + .split_once('.') + .filter(|(_, fraction)| !fraction.is_empty() && fraction.bytes().all(|byte| byte == b'0')) + .map_or(trimmed, |(whole, _)| whole); + parse_int_literal(without_zero_fraction).ok_or_else(|| { + invalid("Input should be a valid integer, unable to parse string as an integer") + }) +} + +/// `TypeAdapter(int).validate_python(value)` in lax mode. +pub fn lax_int(value: &Value) -> Result { + match value { + Value::Bool(flag) => Ok(BigInt::from(u8::from(*flag))), + Value::Int(number) => Ok(number.clone()), + Value::Float(number) if !number.is_finite() => { + Err(invalid("Input should be a finite number")) + } + Value::Float(number) if number.abs() >= I64_LIMIT => Err(invalid( + "Input should be a valid integer, unable to parse number as an integer", + )), + Value::Float(number) => { + let whole = int_from_float(*number)?; + if (number - number.trunc()).is_zero() { + Ok(whole) + } else { + Err(invalid( + "Input should be a valid integer, got a number with a fractional part", + )) + } + } + Value::Str(text) => int_from_text(text), + Value::Bytes(bytes) => int_from_text(&String::from_utf8_lossy(bytes)), + _ => Err(invalid("Input should be a valid integer")), + } +} diff --git a/litellm-rust/crates/python-compat/tests/fixtures.rs b/litellm-rust/crates/python-compat/tests/fixtures.rs index 9c202fdc5f1..cfdfca4dcd4 100644 --- a/litellm-rust/crates/python-compat/tests/fixtures.rs +++ b/litellm-rust/crates/python-compat/tests/fixtures.rs @@ -3,10 +3,10 @@ use std::{collections::BTreeMap, fs::File, io::Write}; use litellm_python_compat::{ - Value, json, + Error, Value, json, literal::literal_eval, - pickle, - repr::{repr, to_str}, + number, pickle, pydantic, + repr::{float_repr, repr, to_str}, truthy::truthy, }; use rstest::{fixture, rstest}; @@ -27,6 +27,31 @@ struct Source { error: Option, } +/// A conversion's result `repr`, or the exception class it raised. +#[derive(Deserialize)] +struct Conversion { + value: Option, + error: Option, +} + +impl Conversion { + fn expected(&self) -> String { + match (&self.value, &self.error) { + (Some(value), None) => value.clone(), + (None, Some(error)) => format!("raises {error}"), + _ => panic!("a conversion records a value or an error"), + } + } +} + +fn outcome(result: Result, show: impl Fn(T) -> String) -> String { + match result { + Ok(value) => show(value), + Err(Error::Conversion { exception, .. }) => format!("raises {exception}"), + Err(error) => format!("unexpected error: {error}"), + } +} + #[derive(Deserialize)] struct Row { name: String, @@ -36,6 +61,9 @@ struct Row { repr: String, str: String, truthy: bool, + int: Conversion, + float: Conversion, + lax_int: Conversion, json: Option, json_error: Option, pickle: Option>, @@ -190,6 +218,24 @@ fn check_value(mismatches: &mut Mismatches, row: &Row, value: &Value) { &row.truthy.to_string(), &truthy(value).to_string(), ); + mismatches.check( + row, + "int", + &row.int.expected(), + &outcome(number::int(value), |int| int.to_string()), + ); + mismatches.check( + row, + "float", + &row.float.expected(), + &outcome(number::float(value), float_repr), + ); + mismatches.check( + row, + "pydantic lax int", + &row.lax_int.expected(), + &outcome(pydantic::lax_int(value), |int| int.to_string()), + ); let expected = row.json.clone().or_else(|| { row.json_error .clone() @@ -208,7 +254,7 @@ fn check_value(mismatches: &mut Mismatches, row: &Row, value: &Value) { } #[rstest] -fn literal_rows_match_python_repr_str_bool_and_json(fixtures: &Fixtures) { +fn literal_rows_match_python_repr_str_bool_numbers_and_json(fixtures: &Fixtures) { let mut mismatches = Mismatches::default(); for row in fixtures.rows.iter().filter(|row| row.literal) { match literal_eval(&row.repr) {