mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-25 23:50:01 +03:00
replace try/except with context manager
This commit is contained in:
parent
e6f59e7260
commit
b78d218fa6
|
@ -1,3 +1,4 @@
|
|||
import contextlib
|
||||
import sys
|
||||
from collections import OrderedDict
|
||||
from collections.abc import Mapping, MutableMapping
|
||||
|
@ -103,15 +104,13 @@ class JSONBoundField(BoundField):
|
|||
# When HTML form input is used and the input is not valid
|
||||
# value will be a JSONString, rather than a JSON primitive.
|
||||
if not getattr(value, 'is_json_string', False):
|
||||
try:
|
||||
with contextlib.suppress(TypeError, ValueError):
|
||||
value = json.dumps(
|
||||
self.value,
|
||||
sort_keys=True,
|
||||
indent=4,
|
||||
separators=(',', ': '),
|
||||
)
|
||||
except (TypeError, ValueError):
|
||||
pass
|
||||
return self.__class__(self._field, value, self.errors, self._prefix)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user