﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
20989	Remove useless list comprehensions	jeroen.pulles@…	nobody	"As I understand it, dict() and tuple() accept iterators, e.g.

{{{
l = [1, 2, 3]
tuple(v for v in l)
}}}

There are various calls to tuple() that place the iterator in a list comprehension before feeding the list to tuple(). For example in django/db/models/sql/query.py:

{{{
aliases = tuple([change_map.get(a, a) for a in aliases])
}}}

can be written as:

{{{
aliases = tuple(change_map.get(a, a) for a in aliases)
}}}

saving two characters, an extra iteration and list creation. The same goes for dict(), where dict([(v, v) for v in l]) can be rewritten as dict((v, v) for v in l).  


----


A shell command like this can replace the calls. When I tried it, I got lots of errors in the unit tests, but my impression was that that didn't have anything to do with the edit... 

{{{
find django/ -name '*.py' -print0 \
    | xargs -n 200 -0 grep -l 'tuple([[][^]]\+[]])' \
    | while read F
do 
    cp ""$F"" ""$F.orig""
    sed -e 's/tuple([[]\(.*\)[]])/tuple(\1)/' ""$F.orig"" > ""$F""
done
}}}
"	Cleanup/optimization	closed	Uncategorized	dev	Normal	fixed			Ready for checkin	1	0	0	0	0	0
