[Django] #32973: Pass generator expression to str.join() instead of list / tuple throughout code base

7 views
Skip to first unread message

Django

unread,
Jul 29, 2021, 7:13:51 PM7/29/21
to django-...@googlegroups.com
#32973: Pass generator expression to str.join() instead of list / tuple throughout
code base
------------------------------------------------+------------------------
Reporter: Chris Jerdonek | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Uncategorized | Version: dev
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
In many places throughout Django's code base, a list or tuple is passed to
`str.join()` when a generator expression would suffice. For example,
instead of `', '.join([self.quote_name(field.column) for field in
fields])` one can do `', '.join(self.quote_name(field.column) for field in
fields)`. This eliminates an unneeded list creation. Many (but not all)
examples can be found by searching the code base for `.join([`.

--
Ticket URL: <https://code.djangoproject.com/ticket/32973>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Jul 29, 2021, 11:58:26 PM7/29/21
to django-...@googlegroups.com
#32973: Pass generator expression to str.join() instead of list / tuple throughout
code base
-------------------------------------+-------------------------------------

Reporter: Chris Jerdonek | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Core (Other) | Version: dev
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => wontfix
* component: Uncategorized => Core (Other)


Comment:

A list comprehension is preferable here as `str.join()` converts to list
internally anyway. It is better performance to provide a list up front.
- https://stackoverflow.com/questions/9060653/list-comprehension-without-
in-python/9061024#9061024
- https://github.com/adamchainz/flake8-comprehensions/issues/156

--
Ticket URL: <https://code.djangoproject.com/ticket/32973#comment:1>

Reply all
Reply to author
Forward
0 new messages