[ORJSONResponse] Handle sets.

This commit is contained in:
Joël Maïzi 2021-01-25 10:44:07 +01:00
parent 54e215b6ff
commit f36a2d8e06
2 changed files with 4 additions and 4 deletions

View File

@ -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):

View File

@ -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)