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
b9a57af6d4
commit
68d0ca6e7e
|
@ -1,3 +1,4 @@
|
|||
import contextlib
|
||||
import copy
|
||||
import datetime
|
||||
import decimal
|
||||
|
@ -690,15 +691,13 @@ class BooleanField(Field):
|
|||
NULL_VALUES = {'null', 'Null', 'NULL', '', None}
|
||||
|
||||
def to_internal_value(self, data):
|
||||
try:
|
||||
with contextlib.suppress(TypeError):
|
||||
if data in self.TRUE_VALUES:
|
||||
return True
|
||||
elif data in self.FALSE_VALUES:
|
||||
return False
|
||||
elif data in self.NULL_VALUES and self.allow_null:
|
||||
return None
|
||||
except TypeError: # Input is an unhashable type
|
||||
pass
|
||||
self.fail('invalid', input=data)
|
||||
|
||||
def to_representation(self, value):
|
||||
|
|
Loading…
Reference in New Issue
Block a user