Opened 3 years ago

Closed 3 years ago

#32973 closed Cleanup/optimization (wontfix)

Pass generator expression to str.join() instead of list / tuple throughout code base

Reported by: Chris Jerdonek Owned by: nobody
Component: Core (Other) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

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([.

Change History (1)

comment:1 by Mariusz Felisiak, 3 years ago

Component: UncategorizedCore (Other)
Resolution: wontfix
Status: newclosed

A list comprehension is preferable here as str.join() converts to list internally anyway. It is better performance to provide a list up front.

Note: See TracTickets for help on using tickets.
Back to Top