From 0214f367bc84d7217e42ae0441d500d31c6a5b78 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Wed, 13 Sep 2017 21:00:45 +0200 Subject: [PATCH] Merged isinstance() calls. --- django/contrib/admin/options.py | 2 +- django/contrib/admin/utils.py | 2 +- django/contrib/postgres/fields/array.py | 2 +- django/forms/models.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/django/contrib/admin/options.py b/django/contrib/admin/options.py index 808f4709ac0..32b30a7e8bc 100644 --- a/django/contrib/admin/options.py +++ b/django/contrib/admin/options.py @@ -134,7 +134,7 @@ class BaseModelAdmin(metaclass=forms.MediaDefiningClass): return self.formfield_for_choice_field(db_field, request, **kwargs) # ForeignKey or ManyToManyFields - if isinstance(db_field, models.ManyToManyField) or isinstance(db_field, models.ForeignKey): + if isinstance(db_field, (models.ForeignKey, models.ManyToManyField)): # Combine the field kwargs with any options for formfield_overrides. # Make sure the passed in **kwargs override anything in # formfield_overrides because **kwargs is more specific, and should diff --git a/django/contrib/admin/utils.py b/django/contrib/admin/utils.py index 5f3a83267dc..9bd4aa7857e 100644 --- a/django/contrib/admin/utils.py +++ b/django/contrib/admin/utils.py @@ -394,7 +394,7 @@ def display_for_field(value, field, empty_value_display): return dict(field.flatchoices).get(value, empty_value_display) # NullBooleanField needs special-case null-handling, so it comes # before the general null test. - elif isinstance(field, models.BooleanField) or isinstance(field, models.NullBooleanField): + elif isinstance(field, (models.BooleanField, models.NullBooleanField)): return _boolean_icon(value) elif value is None: return empty_value_display diff --git a/django/contrib/postgres/fields/array.py b/django/contrib/postgres/fields/array.py index d418e1dc1ad..79927406636 100644 --- a/django/contrib/postgres/fields/array.py +++ b/django/contrib/postgres/fields/array.py @@ -83,7 +83,7 @@ class ArrayField(Field): return '%s[%s]' % (self.base_field.db_type(connection), size) def get_db_prep_value(self, value, connection, prepared=False): - if isinstance(value, list) or isinstance(value, tuple): + if isinstance(value, (list, tuple)): return [self.base_field.get_db_prep_value(i, connection, prepared=False) for i in value] return value diff --git a/django/forms/models.py b/django/forms/models.py index 4435bf9722d..ef934201a9d 100644 --- a/django/forms/models.py +++ b/django/forms/models.py @@ -837,7 +837,7 @@ class BaseModelFormSet(BaseFormSet): pk_value = None except IndexError: pk_value = None - if isinstance(pk, OneToOneField) or isinstance(pk, ForeignKey): + if isinstance(pk, (ForeignKey, OneToOneField)): qs = pk.remote_field.model._default_manager.get_queryset() else: qs = self.model._default_manager.get_queryset()