replace try/except with context manager

This commit is contained in:
ahzam 2022-09-28 01:15:16 +05:00
parent b9a57af6d4
commit 68d0ca6e7e

View File

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