diff --git a/django/contrib/sessions/backends/base.py b/django/contrib/sessions/backends/base.py index 64955b8bb7..d469dab44d 100644 --- a/django/contrib/sessions/backends/base.py +++ b/django/contrib/sessions/backends/base.py @@ -142,7 +142,7 @@ class SessionBase: def is_empty(self): "Return True when there is no session_key and the session is empty." try: - return not bool(self._session_key) and not self._session_cache + return not self._session_key and not self._session_cache except AttributeError: return True diff --git a/django/core/validators.py b/django/core/validators.py index 07236b7d26..15a8beafe2 100644 --- a/django/core/validators.py +++ b/django/core/validators.py @@ -54,7 +54,7 @@ class RegexValidator: Validate that the input contains (or does *not* contain, if inverse_match is True) a match for the regular expression. """ - regex_matches = bool(self.regex.search(str(value))) + regex_matches = self.regex.search(str(value)) invalid_input = regex_matches if self.inverse_match else not regex_matches if invalid_input: raise ValidationError(self.message, code=self.code) diff --git a/django/db/models/sql/compiler.py b/django/db/models/sql/compiler.py index 2b0590de3a..9e381fd269 100644 --- a/django/db/models/sql/compiler.py +++ b/django/db/models/sql/compiler.py @@ -1215,12 +1215,10 @@ class SQLInsertCompiler(SQLCompiler): qn = self.connection.ops.quote_name opts = self.query.get_meta() result = ['INSERT INTO %s' % qn(opts.db_table)] - - has_fields = bool(self.query.fields) - fields = self.query.fields if has_fields else [opts.pk] + fields = self.query.fields or [opts.pk] result.append('(%s)' % ', '.join(qn(f.column) for f in fields)) - if has_fields: + if self.query.fields: value_rows = [ [self.prepare_value(field, self.pre_save_val(field, obj)) for field in fields] for obj in self.query.objs diff --git a/django/forms/forms.py b/django/forms/forms.py index e2e7c645ff..a43f80996b 100644 --- a/django/forms/forms.py +++ b/django/forms/forms.py @@ -139,7 +139,7 @@ class BaseForm: if self._errors is None: is_valid = "Unknown" else: - is_valid = self.is_bound and not bool(self._errors) + is_valid = self.is_bound and not self._errors return '<%(cls)s bound=%(bound)s, valid=%(valid)s, fields=(%(fields)s)>' % { 'cls': self.__class__.__name__, 'bound': self.is_bound, diff --git a/django/forms/widgets.py b/django/forms/widgets.py index 498185fe23..c758b36e91 100644 --- a/django/forms/widgets.py +++ b/django/forms/widgets.py @@ -681,7 +681,7 @@ class Select(ChoiceWidget): def _choice_has_empty_value(choice): """Return True if the choice's value is empty string or None.""" value, _ = choice - return (isinstance(value, str) and not bool(value)) or value is None + return (isinstance(value, str) and not value) or value is None def use_required_attribute(self, initial): """ diff --git a/django/template/backends/base.py b/django/template/backends/base.py index c47c95e51e..22628c6355 100644 --- a/django/template/backends/base.py +++ b/django/template/backends/base.py @@ -20,7 +20,7 @@ class BaseEngine: params = params.copy() self.name = params.pop('NAME') self.dirs = list(params.pop('DIRS')) - self.app_dirs = bool(params.pop('APP_DIRS')) + self.app_dirs = params.pop('APP_DIRS') if params: raise ImproperlyConfigured( "Unknown parameters: {}".format(", ".join(params))) diff --git a/django/utils/http.py b/django/utils/http.py index 7e4e58229f..c1c616a6fd 100644 --- a/django/utils/http.py +++ b/django/utils/http.py @@ -324,7 +324,6 @@ def _urlsplit(url, scheme='', allow_fragments=True): Note that we don't break the components up in smaller bits (e.g. netloc is a single string) and we don't expand % escapes.""" url, scheme, _coerce_result = _coerce_args(url, scheme) - allow_fragments = bool(allow_fragments) netloc = query = fragment = '' i = url.find(':') if i > 0: