#28860: Reduce calls to len() -------------------------------------+------------------------------------- Reporter: Дилян Палаузов | Owner: nobody Type: | Status: new Cleanup/optimization | Component: Core (Other) | Version: master Severity: Normal | Resolution: Keywords: | Triage Stage: Ready for | checkin Has patch: 1 | Needs documentation: 0 Needs tests: 0 | Patch needs improvement: 0 Easy pickings: 0 | UI/UX: 0 -------------------------------------+-------------------------------------
Comment (by Дилян Палаузов): Even more places: {{{ diff --git a/django/contrib/admin/filters.py b/django/contrib/admin/filters.py --- a/django/contrib/admin/filters.py +++ b/django/contrib/admin/filters.py @@ -77,7 +77,7 @@ class SimpleListFilter(ListFilter): self.lookup_choices = list(lookup_choices) def has_output(self): - return len(self.lookup_choices) > 0 + return bool(self.lookup_choices) def value(self): """ diff --git a/django/db/backends/oracle/creation.py b/django/db/backends/oracle/creation.py --- a/django/db/backends/oracle/creation.py +++ b/django/db/backends/oracle/creation.py @@ -268,7 +268,7 @@ class DatabaseCreation(BaseDatabaseCreation): """ try: # Statement can fail when acceptable_ora_err is not None - allow_quiet_fail = acceptable_ora_err is not None and len(acceptable_ora_err) > 0 + allow_quiet_fail = bool(acceptable_ora_err) self._execute_statements(cursor, statements, parameters, verbosity, allow_quiet_fail=allow_quiet_fa return True except DatabaseError as err: diff --git a/django/db/migrations/questioner.py b/django/db/migrations/questioner.py --- a/django/db/migrations/questioner.py +++ b/django/db/migrations/questioner.py @@ -85,7 +85,7 @@ class InteractiveMigrationQuestioner(MigrationQuestioner): result = input("%s " % question) if not result and default is not None: return default - while len(result) < 1 or result[0].lower() not in "yn": + while not result or result[0].lower() not in "yn": result = input("Please answer yes or no: ") return result[0].lower() == "y" diff --git a/django/db/models/base.py b/django/db/models/base.py --- a/django/db/models/base.py +++ b/django/db/models/base.py @@ -736,7 +736,7 @@ class Model(metaclass=ModelBase): """ using = using or router.db_for_write(self.__class__, instance=self) assert not (force_insert and (force_update or update_fields)) - assert update_fields is None or len(update_fields) > 0 + assert update_fields is None or update_fields cls = origin = self.__class__ # Skip proxies, but keep the origin as the proxy model. if cls._meta.proxy: }}} -- Ticket URL: <https://code.djangoproject.com/ticket/28860#comment:2> 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 django-updates+unsubscr...@googlegroups.com. To post to this group, send email to django-updates@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/django-updates/072.91891f72fb3d910e7ae0d3c253b0b28a%40djangoproject.com. For more options, visit https://groups.google.com/d/optout.