Skip to content

Commit

Permalink
fix(json): Convert Python tuple to JSON array
Browse files Browse the repository at this point in the history
Fix #19
  • Loading branch information
LukeSavefrogs committed Feb 12, 2024
1 parent 6a15bf8 commit 5c3e89d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/polyfills/json/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
9 changes: 8 additions & 1 deletion src/polyfills/json/tests/dumps/test_dumps.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)


Expand Down

0 comments on commit 5c3e89d

Please sign in to comment.