From 5c3e89d03a74cf2fbc654d77efa026d78507a4a8 Mon Sep 17 00:00:00 2001 From: Luca Salvarani Date: Mon, 12 Feb 2024 14:39:33 +0100 Subject: [PATCH] fix(json): Convert Python tuple to JSON array Fix #19 --- src/polyfills/json/__init__.py | 2 +- src/polyfills/json/tests/dumps/test_dumps.py | 9 ++++++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/polyfills/json/__init__.py b/src/polyfills/json/__init__.py index e968234..6f4f23f 100644 --- a/src/polyfills/json/__init__.py +++ b/src/polyfills/json/__init__.py @@ -108,7 +108,7 @@ def dumps( # ---> Handle JSON arrays - elif obj_type == type([]): + elif obj_type in [type([None,]), type((None,))]: obj_string_parts.append("[") for item in obj: if len(obj_string_parts) > 1: diff --git a/src/polyfills/json/tests/dumps/test_dumps.py b/src/polyfills/json/tests/dumps/test_dumps.py index 2155daa..bf43023 100644 --- a/src/polyfills/json/tests/dumps/test_dumps.py +++ b/src/polyfills/json/tests/dumps/test_dumps.py @@ -103,7 +103,14 @@ def test_empty(self): def test_simple(self): self.assertEqual( json.dumps(["", "test1", "", "test2", ""]), - '["", "test1", "", "test2", ""]' + '["", "test1", "", "test2", ""]', + "List should be converted to JSON array" + ) + + self.assertEqual( + json.dumps(("", "test1", "", "test2", "")), + '["", "test1", "", "test2", ""]', + "Tuple should be converted to JSON array" )