Skip to content

Commit 166f174

Browse files
authored
Fix is_jsonable if integer key in dict (#2857)
1 parent 0c1e566 commit 166f174

File tree

2 files changed

+2
-1
lines changed

2 files changed

+2
-1
lines changed

src/huggingface_hub/utils/_typing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def is_jsonable(obj: Any) -> bool:
5050
if isinstance(obj, (list, tuple)):
5151
return all(is_jsonable(item) for item in obj)
5252
if isinstance(obj, dict):
53-
return all(isinstance(key, str) and is_jsonable(value) for key, value in obj.items())
53+
return all(isinstance(key, _JSON_SERIALIZABLE_TYPES) and is_jsonable(value) for key, value in obj.items())
5454
if hasattr(obj, "__json__"):
5555
return True
5656
return False

tests/test_utils_typing.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ class CustomType:
3232
[(1, 2.0, "string"), True],
3333
{},
3434
{"name": "Alice", "age": 30},
35+
{0: "LABEL_0", 1.0: "LABEL_1"},
3536
],
3637
)
3738
def test_is_jsonable_success(data):

0 commit comments

Comments
 (0)