[ORJSONResponse] Handle sets.
This commit is contained in:
parent
54e215b6ff
commit
f36a2d8e06
|
@ -62,7 +62,7 @@ class ORJSONResponse(JSONResponse):
|
||||||
decimal.Decimal
|
decimal.Decimal
|
||||||
}
|
}
|
||||||
list_types = {
|
list_types = {
|
||||||
type(set)
|
set
|
||||||
}
|
}
|
||||||
|
|
||||||
if type(x) in str_types:
|
if type(x) in str_types:
|
||||||
|
@ -70,7 +70,7 @@ class ORJSONResponse(JSONResponse):
|
||||||
if type(x) in list_types:
|
if type(x) in list_types:
|
||||||
return list(x)
|
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):
|
class HJSONResponse(ORJSONResponse):
|
||||||
|
|
|
@ -8,7 +8,7 @@ def test_orjson():
|
||||||
test_obj = {
|
test_obj = {
|
||||||
"ok": "ko",
|
"ok": "ko",
|
||||||
"dec": decimal.Decimal(42),
|
"dec": decimal.Decimal(42),
|
||||||
"set": set([0,4,2])
|
"set": {0, 4, 2}
|
||||||
}
|
}
|
||||||
|
|
||||||
resp = ORJSONResponse(test_obj)
|
resp = ORJSONResponse(test_obj)
|
||||||
|
@ -18,4 +18,4 @@ def test_orjson():
|
||||||
assert 'ok' in test_obj_dec.keys()
|
assert 'ok' in test_obj_dec.keys()
|
||||||
assert isinstance(test_obj_dec['ok'], str)
|
assert isinstance(test_obj_dec['ok'], str)
|
||||||
assert isinstance(test_obj_dec['dec'], str)
|
assert isinstance(test_obj_dec['dec'], str)
|
||||||
assert isinstance(test_obj_dec['set'], liststr)
|
assert isinstance(test_obj_dec['set'], list)
|
||||||
|
|
Loading…
Reference in New Issue