From 68d0ca6e7e67214b2e5fd8638f130b29e9790462 Mon Sep 17 00:00:00 2001 From: ahzam Date: Wed, 28 Sep 2022 01:15:16 +0500 Subject: [PATCH] replace try/except with context manager --- rest_framework/fields.py | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/rest_framework/fields.py b/rest_framework/fields.py index 6374c1ea9..a3695b912 100644 --- a/rest_framework/fields.py +++ b/rest_framework/fields.py @@ -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):