Opened 4 years ago
Closed 4 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 , 4 years ago
| Component: | Uncategorized → Core (Other) |
|---|---|
| Resolution: | → wontfix |
| Status: | new → closed |
Note:
See TracTickets
for help on using tickets.
A list comprehension is preferable here as
str.join()converts to list internally anyway. It is better performance to provide a list up front.