#28906: Reduce calls to bool()
------------------------------------------------+------------------------
Reporter: Дилян Палаузов | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Uncategorized | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
Compared to the attached patch, these changes might be more controversial:
{{{
diff --git a/django/contrib/gis/db/backends/spatialite/features.py
b/django/contrib/gis/db/backends/spatialite/features
--- a/django/contrib/gis/db/backends/spatialite/features.py
+++ b/django/contrib/gis/db/backends/spatialite/features.py
@@ -10,4 +10,4 @@ class DatabaseFeatures(BaseSpatialFeatures,
SQLiteDatabaseFeatures):
@cached_property
def supports_area_geodetic(self):
- return bool(self.connection.ops.lwgeom_version())
+ return self.connection.ops.lwgeom_version()
diff --git a/django/db/models/sql/compiler.py
b/django/db/models/sql/compiler.py
--- a/django/db/models/sql/compiler.py
+++ b/django/db/models/sql/compiler.py
@@ -51,7 +51,7 @@ class SQLCompiler:
order_by = self.get_order_by()
self.where, self.having = self.query.where.split_having()
extra_select = self.get_extra_select(order_by, self.select)
- self.has_extra_select = bool(extra_select)
+ self.has_extra_select = extra_select
group_by = self.get_group_by(self.select + extra_select,
order_by)
return extra_select, order_by, group_by
@@ -1216,11 +1216,10 @@ class SQLInsertCompiler(SQLCompiler):
insert_statement =
self.connection.ops.insert_statement(on_conflict=self.query.on_conflict)
result = ['%s %s' % (insert_statement, 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
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/28906>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/057.d69da48816525ccb1c9eff9bf7a441d0%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.