From f36a2d8e06b9004471b574ee1b518533e4666d48 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=ABl=20Ma=C3=AFzi?= Date: Mon, 25 Jan 2021 10:44:07 +0100 Subject: [PATCH] [ORJSONResponse] Handle sets. --- halfapi/lib/responses.py | 4 ++-- tests/test_lib_responses.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/halfapi/lib/responses.py b/halfapi/lib/responses.py index 0ed2f1f..7fb0acc 100644 --- a/halfapi/lib/responses.py +++ b/halfapi/lib/responses.py @@ -62,7 +62,7 @@ class ORJSONResponse(JSONResponse): decimal.Decimal } list_types = { - type(set) + set } if type(x) in str_types: @@ -70,7 +70,7 @@ class ORJSONResponse(JSONResponse): if type(x) in list_types: return list(x) - raise TypeError(f'Type {type(x)} is not handled in ORJSONResponse') + raise TypeError(f'Type {type(x)} is not handled by ORJSONResponse') class HJSONResponse(ORJSONResponse): diff --git a/tests/test_lib_responses.py b/tests/test_lib_responses.py index c63fea8..3f66441 100644 --- a/tests/test_lib_responses.py +++ b/tests/test_lib_responses.py @@ -8,7 +8,7 @@ def test_orjson(): test_obj = { "ok": "ko", "dec": decimal.Decimal(42), - "set": set([0,4,2]) + "set": {0, 4, 2} } resp = ORJSONResponse(test_obj) @@ -18,4 +18,4 @@ def test_orjson(): assert 'ok' in test_obj_dec.keys() assert isinstance(test_obj_dec['ok'], str) assert isinstance(test_obj_dec['dec'], str) - assert isinstance(test_obj_dec['set'], liststr) + assert isinstance(test_obj_dec['set'], list)