Permalink
Browse files

Fixed #20989 -- Removed useless explicit list comprehensions.

  • Loading branch information...
1 parent e4a67fd commit 11cd7388f77aa9d12ab6b57285c3801b237e241b @charettes charettes committed Aug 29, 2013
Showing with 163 additions and 163 deletions.
  1. +2 −2 django/contrib/admin/filters.py
  2. +1 −1 django/contrib/admin/helpers.py
  3. +3 −3 django/contrib/admin/options.py
  4. +3 −3 django/contrib/admin/widgets.py
  5. +1 −1 django/contrib/admindocs/utils.py
  6. +2 −2 django/contrib/auth/backends.py
  7. +2 −2 django/contrib/auth/forms.py
  8. +2 −2 django/contrib/contenttypes/management.py
  9. +1 −1 django/contrib/gis/db/models/sql/aggregates.py
  10. +1 −1 django/contrib/gis/feeds.py
  11. +5 −5 django/contrib/gis/gdal/geometries.py
  12. +1 −1 django/contrib/gis/geos/collections.py
  13. +2 −2 django/contrib/gis/geos/coordseq.py
  14. +3 −3 django/contrib/gis/geos/polygon.py
  15. +3 −3 django/contrib/gis/geos/tests/test_geos.py
  16. +2 −2 django/contrib/gis/management/commands/ogrinspect.py
  17. +1 −1 django/contrib/gis/maps/google/gmap.py
  18. +1 −1 django/contrib/gis/maps/google/overlays.py
  19. +1 −1 django/contrib/gis/tests/geoadmin/tests.py
  20. +1 −1 django/contrib/gis/tests/geoapp/test_feeds.py
  21. +1 −1 django/contrib/gis/tests/geoapp/test_sitemaps.py
  22. +5 −5 django/contrib/gis/utils/wkt.py
  23. +2 −2 django/contrib/messages/storage/cookie.py
  24. +1 −1 django/contrib/webdesign/lorem_ipsum.py
  25. +1 −1 django/core/cache/utils.py
  26. +3 −3 django/core/management/__init__.py
  27. +1 −1 django/core/management/commands/migrate.py
  28. +1 −1 django/core/management/sql.py
  29. +1 −1 django/core/management/utils.py
  30. +1 −1 django/core/management/validation.py
  31. +3 −3 django/core/urlresolvers.py
  32. +1 −1 django/db/backends/__init__.py
  33. +1 −1 django/db/backends/mysql/compiler.py
  34. +2 −2 django/db/backends/mysql/introspection.py
  35. +4 −4 django/db/backends/oracle/base.py
  36. +1 −1 django/db/backends/oracle/introspection.py
  37. +2 −2 django/db/backends/sqlite3/schema.py
  38. +2 −2 django/db/migrations/autodetector.py
  39. +1 −1 django/db/migrations/writer.py
  40. +2 −2 django/db/models/base.py
  41. +2 −2 django/db/models/deletion.py
  42. +1 −1 django/db/models/options.py
  43. +1 −1 django/db/models/query.py
  44. +1 −1 django/db/models/sql/aggregates.py
  45. +4 −4 django/db/models/sql/compiler.py
  46. +7 −7 django/db/models/sql/query.py
  47. +2 −2 django/forms/fields.py
  48. +3 −3 django/forms/formsets.py
  49. +3 −3 django/forms/models.py
  50. +2 −2 django/forms/util.py
  51. +3 −3 django/template/base.py
  52. +5 −5 django/template/defaulttags.py
  53. +2 −2 django/template/loader_tags.py
  54. +3 −3 django/test/_doctest.py
  55. +5 −5 django/utils/cache.py
  56. +2 −2 django/utils/checksums.py
  57. +1 −1 django/utils/crypto.py
  58. +1 −1 django/utils/datastructures.py
  59. +3 −3 django/utils/html.py
  60. +2 −2 django/utils/termcolors.py
  61. +1 −1 django/utils/text.py
  62. +1 −1 django/utils/translation/__init__.py
  63. +1 −1 tests/backends/tests.py
  64. +2 −2 tests/file_uploads/views.py
  65. +1 −1 tests/forms_tests/tests/test_error_messages.py
  66. +1 −1 tests/forms_tests/tests/test_extra.py
  67. +3 −3 tests/forms_tests/tests/test_forms.py
  68. +1 −1 tests/forms_tests/tests/test_formsets.py
  69. +4 −4 tests/forms_tests/tests/test_widgets.py
  70. +1 −1 tests/proxy_models/tests.py
  71. +2 −2 tests/schema/tests.py
  72. +2 −2 tests/servers/views.py
  73. +1 −1 tests/syndication/tests.py
  74. +14 −14 tests/template_tests/templatetags/custom.py
  75. +1 −1 tests/template_tests/tests.py
@@ -287,8 +287,8 @@ def choices(self, cl):
class DateFieldListFilter(FieldListFilter):
def __init__(self, field, request, params, model, model_admin, field_path):
self.field_generic = '%s__' % field_path
- self.date_params = dict([(k, v) for k, v in params.items()
- if k.startswith(self.field_generic)])
+ self.date_params = dict((k, v) for k, v in params.items()
+ if k.startswith(self.field_generic))
now = timezone.now()
# When time zone support is enabled, convert "now" to the user's time
@@ -112,7 +112,7 @@ def __iter__(self):
yield AdminField(self.form, field, is_first=(i == 0))
def errors(self):
- return mark_safe('\n'.join([self.form[f].errors.as_ul() for f in self.fields if f not in self.readonly_fields]).strip('\n'))
+ return mark_safe('\n'.join(self.form[f].errors.as_ul() for f in self.fields if f not in self.readonly_fields).strip('\n'))
class AdminField(object):
def __init__(self, form, field, is_first):
@@ -698,16 +698,16 @@ def get_actions(self, request):
# Avoid trying to iterate over None
if not class_actions:
continue
- actions.extend([self.get_action(action) for action in class_actions])
+ actions.extend(self.get_action(action) for action in class_actions)
# get_action might have returned None, so filter any of those out.
actions = filter(None, actions)
# Convert the actions into an OrderedDict keyed by name.
- actions = OrderedDict([
+ actions = OrderedDict(
(name, (func, name, desc))
for func, name, desc in actions
- ])
+ )
return actions
@@ -119,7 +119,7 @@ def url_params_from_lookup_dict(lookups):
if callable(v):
v = v()
if isinstance(v, (tuple, list)):
- v = ','.join([str(x) for x in v])
+ v = ','.join(str(x) for x in v)
elif isinstance(v, bool):
# See django.db.fields.BooleanField.get_prep_lookup
v = ('0', '1')[v]
@@ -154,7 +154,7 @@ def render(self, name, value, attrs=None):
params = self.url_parameters()
if params:
- url = '?' + '&'.join(['%s=%s' % (k, v) for k, v in params.items()])
+ url = '?' + '&'.join('%s=%s' % (k, v) for k, v in params.items())
else:
url = ''
if "class" not in attrs:
@@ -199,7 +199,7 @@ def render(self, name, value, attrs=None):
# The related object is registered with the same AdminSite
attrs['class'] = 'vManyToManyRawIdAdminField'
if value:
- value = ','.join([force_text(v) for v in value])
+ value = ','.join(force_text(v) for v in value)
else:
value = ''
return super(ManyToManyRawIdWidget, self).render(name, value, attrs)
@@ -26,7 +26,7 @@ def trim_docstring(docstring):
return ''
# Convert tabs to spaces and split into lines
lines = docstring.expandtabs().splitlines()
- indent = min([len(line) - len(line.lstrip()) for line in lines if line.lstrip()])
+ indent = min(len(line) - len(line.lstrip()) for line in lines if line.lstrip())
trimmed = [lines[0].lstrip()] + [line[indent:].rstrip() for line in lines[1:]]
return "\n".join(trimmed).strip()
@@ -36,14 +36,14 @@ def get_group_permissions(self, user_obj, obj=None):
user_groups_query = 'group__%s' % user_groups_field.related_query_name()
perms = Permission.objects.filter(**{user_groups_query: user_obj})
perms = perms.values_list('content_type__app_label', 'codename').order_by()
- user_obj._group_perm_cache = set(["%s.%s" % (ct, name) for ct, name in perms])
+ user_obj._group_perm_cache = set("%s.%s" % (ct, name) for ct, name in perms)
return user_obj._group_perm_cache
def get_all_permissions(self, user_obj, obj=None):
if user_obj.is_anonymous() or obj is not None:
return set()
if not hasattr(user_obj, '_perm_cache'):
- user_obj._perm_cache = set(["%s.%s" % (p.content_type.app_label, p.codename) for p in user_obj.user_permissions.select_related()])
+ user_obj._perm_cache = set("%s.%s" % (p.content_type.app_label, p.codename) for p in user_obj.user_permissions.select_related())
user_obj._perm_cache.update(self.get_group_permissions(user_obj))
return user_obj._perm_cache
@@ -330,10 +330,10 @@ def clean_old_password(self):
)
return old_password
-PasswordChangeForm.base_fields = OrderedDict([
+PasswordChangeForm.base_fields = OrderedDict(
(k, PasswordChangeForm.base_fields[k])
for k in ['old_password', 'new_password1', 'new_password2']
-])
+)
class AdminPasswordChangeForm(forms.Form):
@@ -58,10 +58,10 @@ def update_contenttypes(app, created_models, verbosity=2, db=DEFAULT_DB_ALIAS, *
# Confirm that the content type is stale before deletion.
if to_remove:
if kwargs.get('interactive', False):
- content_type_display = '\n'.join([
+ content_type_display = '\n'.join(
' %s | %s' % (ct.app_label, ct.model)
for ct in to_remove
- ])
+ )
ok_to_delete = input("""The following content types are stale and need to be deleted:
%s
@@ -32,7 +32,7 @@ def as_sql(self, qn, connection):
if hasattr(self.col, 'as_sql'):
field_name, params = self.col.as_sql(qn, connection)
elif isinstance(self.col, (list, tuple)):
- field_name = '.'.join([qn(c) for c in self.col])
+ field_name = '.'.join(qn(c) for c in self.col)
else:
field_name = self.col
@@ -15,7 +15,7 @@ def georss_coords(self, coords):
a single white space. Given a tuple of coordinates, this will return
a unicode GeoRSS representation.
"""
- return ' '.join(['%f %f' % (coord[1], coord[0]) for coord in coords])
+ return ' '.join('%f %f' % (coord[1], coord[0]) for coord in coords)
def add_georss_point(self, handler, coords, w3c_geo=False):
"""
@@ -575,7 +575,7 @@ def __len__(self):
@property
def tuple(self):
"Returns the tuple representation of this LineString."
- return tuple([self[i] for i in xrange(len(self))])
+ return tuple(self[i] for i in xrange(len(self)))
coords = tuple
def _listarr(self, func):
@@ -632,14 +632,14 @@ def shell(self):
@property
def tuple(self):
"Returns a tuple of LinearRing coordinate tuples."
- return tuple([self[i].tuple for i in xrange(self.geom_count)])
+ return tuple(self[i].tuple for i in xrange(self.geom_count))
coords = tuple
@property
def point_count(self):
"The number of Points in this Polygon."
# Summing up the number of points in each ring of the Polygon.
- return sum([self[i].point_count for i in xrange(self.geom_count)])
+ return sum(self[i].point_count for i in xrange(self.geom_count))
@property
def centroid(self):
@@ -686,12 +686,12 @@ def add(self, geom):
def point_count(self):
"The number of Points in this Geometry Collection."
# Summing up the number of points in each geometry in this collection
- return sum([self[i].point_count for i in xrange(self.geom_count)])
+ return sum(self[i].point_count for i in xrange(self.geom_count))
@property
def tuple(self):
"Returns a tuple representation of this Geometry Collection."
- return tuple([self[i].tuple for i in xrange(self.geom_count)])
+ return tuple(self[i].tuple for i in xrange(self.geom_count))
coords = tuple
# Multiple Geometry types.
@@ -82,7 +82,7 @@ def _set_list(self, length, items):
@property
def kml(self):
"Returns the KML for this Geometry Collection."
- return '<MultiGeometry>%s</MultiGeometry>' % ''.join([g.kml for g in self])
+ return '<MultiGeometry>%s</MultiGeometry>' % ''.join(g.kml for g in self)
@property
def tuple(self):
@@ -147,11 +147,11 @@ def kml(self):
if self.hasz: substr = '%s,%s,%s '
else: substr = '%s,%s,0 '
return '<coordinates>%s</coordinates>' % \
- ''.join([substr % self[i] for i in xrange(len(self))]).strip()
+ ''.join(substr % self[i] for i in xrange(len(self))).strip()
@property
def tuple(self):
"Returns a tuple version of this coordinate sequence."
n = self.size
if n == 1: return self[0]
- else: return tuple([self[i] for i in xrange(n)])
+ else: return tuple(self[i] for i in xrange(n))
@@ -159,12 +159,12 @@ def _set_ext_ring(self, ring):
@property
def tuple(self):
"Gets the tuple for each ring in this Polygon."
- return tuple([self[i].tuple for i in xrange(len(self))])
+ return tuple(self[i].tuple for i in xrange(len(self)))
coords = tuple
@property
def kml(self):
"Returns the KML representation of this Polygon."
- inner_kml = ''.join(["<innerBoundaryIs>%s</innerBoundaryIs>" % self[i+1].kml
- for i in xrange(self.num_interior_rings)])
+ inner_kml = ''.join("<innerBoundaryIs>%s</innerBoundaryIs>" % self[i+1].kml
+ for i in xrange(self.num_interior_rings))
return "<Polygon><outerBoundaryIs>%s</outerBoundaryIs>%s</Polygon>" % (self[0].kml, inner_kml)
@@ -838,9 +838,9 @@ def test_collections_of_collections(self):
# Creating a GeometryCollection WKT string composed of other
# collections and polygons.
coll = [mp.wkt for mp in self.geometries.multipolygons if mp.valid]
- coll.extend([mls.wkt for mls in self.geometries.multilinestrings])
- coll.extend([p.wkt for p in self.geometries.polygons])
- coll.extend([mp.wkt for mp in self.geometries.multipoints])
+ coll.extend(mls.wkt for mls in self.geometries.multilinestrings)
+ coll.extend(p.wkt for p in self.geometries.polygons)
+ coll.extend(mp.wkt for mp in self.geometries.multipoints)
gc_wkt = 'GEOMETRYCOLLECTION(%s)' % ','.join(coll)
# Should construct ok from WKT
@@ -113,6 +113,6 @@ def handle(self, *args, **options):
rev_mapping = dict((v, k) for k, v in mapping_dict.items())
output.extend(['', '# Auto-generated `LayerMapping` dictionary for %s model' % model_name,
'%s_mapping = {' % model_name.lower()])
- output.extend([" '%s' : '%s'," % (rev_mapping[ogr_fld], ogr_fld) for ogr_fld in ds[options['layer_key']].fields])
- output.extend([" '%s' : '%s'," % (options['geom_name'], mapping_dict[options['geom_name']]), '}'])
+ output.extend(" '%s' : '%s'," % (rev_mapping[ogr_fld], ogr_fld) for ogr_fld in ds[options['layer_key']].fields)
+ output.extend(" '%s' : '%s'," % (options['geom_name'], mapping_dict[options['geom_name']]), '}')
return '\n'.join(output) + '\n'
@@ -150,7 +150,7 @@ def xhtml(self):
@property
def icons(self):
"Returns a sequence of GIcon objects in this map."
- return set([marker.icon for marker in self.markers if marker.icon])
+ return set(marker.icon for marker in self.markers if marker.icon)
class GoogleMapSet(GoogleMap):
@@ -61,7 +61,7 @@ def __init__(self):
def latlng_from_coords(self, coords):
"Generates a JavaScript array of GLatLng objects for the given coordinates."
- return '[%s]' % ','.join(['new GLatLng(%s,%s)' % (y, x) for x, y in coords])
+ return '[%s]' % ','.join('new GLatLng(%s,%s)' % (y, x) for x, y in coords)
def add_event(self, event):
"Attaches a GEvent to the overlay object."
@@ -23,7 +23,7 @@ class GeoAdminTest(TestCase):
def test_ensure_geographic_media(self):
geoadmin = admin.site._registry[City]
admin_js = geoadmin.media.render_js()
- self.assertTrue(any([geoadmin.openlayers_url in js for js in admin_js]))
+ self.assertTrue(any(geoadmin.openlayers_url in js for js in admin_js))
def test_olmap_OSM_rendering(self):
geoadmin = admin.site._registry[City]
@@ -28,7 +28,7 @@ def tearDown(self):
def assertChildNodes(self, elem, expected):
"Taken from syndication/tests.py."
- actual = set([n.nodeName for n in elem.childNodes])
+ actual = set(n.nodeName for n in elem.childNodes)
expected = set(expected)
self.assertEqual(actual, expected)
@@ -32,7 +32,7 @@ def tearDown(self):
def assertChildNodes(self, elem, expected):
"Taken from syndication/tests.py."
- actual = set([n.nodeName for n in elem.childNodes])
+ actual = set(n.nodeName for n in elem.childNodes)
expected = set(expected)
self.assertEqual(actual, expected)
@@ -30,10 +30,10 @@ def precision_wkt(geom, prec):
coord_fmt = ' '.join([num_fmt, num_fmt])
def formatted_coords(coords):
- return ','.join([coord_fmt % c[:2] for c in coords])
+ return ','.join(coord_fmt % c[:2] for c in coords)
def formatted_poly(poly):
- return ','.join(['(%s)' % formatted_coords(r) for r in poly])
+ return ','.join('(%s)' % formatted_coords(r) for r in poly)
def formatted_geom(g):
gtype = str(g.geom_type).upper()
@@ -47,11 +47,11 @@ def formatted_geom(g):
elif gtype == 'MULTIPOINT':
yield formatted_coords(g.coords)
elif gtype == 'MULTIPOLYGON':
- yield ','.join(['(%s)' % formatted_poly(p) for p in g])
+ yield ','.join('(%s)' % formatted_poly(p) for p in g)
elif gtype == 'GEOMETRYCOLLECTION':
- yield ','.join([''.join([wkt for wkt in formatted_geom(child)]) for child in g])
+ yield ','.join(''.join(wkt for wkt in formatted_geom(child)) for child in g)
else:
raise TypeError
yield ')'
- return ''.join([wkt for wkt in formatted_geom(geom)])
+ return ''.join(wkt for wkt in formatted_geom(geom))
@@ -38,8 +38,8 @@ def process_messages(self, obj):
return Message(*obj[2:])
return [self.process_messages(item) for item in obj]
if isinstance(obj, dict):
- return dict([(key, self.process_messages(value))
- for key, value in six.iteritems(obj)])
+ return dict((key, self.process_messages(value))
+ for key, value in six.iteritems(obj))
return obj
def decode(self, s, **kwargs):
@@ -62,7 +62,7 @@ def paragraph():
The paragraph consists of between 1 and 4 sentences, inclusive.
"""
- return ' '.join([sentence() for i in range(random.randint(1, 4))])
+ return ' '.join(sentence() for i in range(random.randint(1, 4)))
def paragraphs(count, common=True):
"""
@@ -10,6 +10,6 @@
def make_template_fragment_key(fragment_name, vary_on=None):
if vary_on is None:
vary_on = ()
- key = ':'.join([urlquote(var) for var in vary_on])
+ key = ':'.join(urlquote(var) for var in vary_on)
args = hashlib.md5(force_bytes(key))
return TEMPLATE_FRAGMENT_KEY_TEMPLATE % (fragment_name, args.hexdigest())
@@ -114,8 +114,8 @@ def get_commands():
for app_name in apps:
try:
path = find_management_module(app_name)
- _commands.update(dict([(name, app_name)
- for name in find_commands(path)]))
+ _commands.update(dict((name, app_name)
+ for name in find_commands(path)))
except ImportError:
pass # No management module - ignore this app
@@ -336,7 +336,7 @@ def autocomplete(self):
options = [opt for opt in options if opt[0] not in prev_opts]
# filter options by current input
- options = sorted([(k, v) for k, v in options if k.startswith(curr)])
+ options = sorted((k, v) for k, v in options if k.startswith(curr))
for option in options:
opt_label = option[0]
# append '=' to options which require args
@@ -164,7 +164,7 @@ def model_installed(model):
for app_name, model_list in all_models
)
- create_models = set([x for x in itertools.chain(*manifest.values())])
+ create_models = set(itertools.chain(*manifest.values()))
emit_pre_migrate_signal(create_models, self.verbosity, self.interactive, connection.alias)
# Create the tables for each model
@@ -29,7 +29,7 @@ def sql_create(app, style, connection):
app_models = models.get_models(app, include_auto_created=True)
final_output = []
tables = connection.introspection.table_names()
- known_models = set([model for model in connection.introspection.installed_models(tables) if model not in app_models])
+ known_models = set(model for model in connection.introspection.installed_models(tables) if model not in app_models)
pending_references = {}
for model in app_models:
@@ -52,7 +52,7 @@ def handle_extensions(extensions=('html',), ignored=('py',)):
for i, ext in enumerate(ext_list):
if not ext.startswith('.'):
ext_list[i] = '.%s' % ext_list[i]
- return set([x for x in ext_list if x.strip('.') not in ignored])
+ return set(x for x in ext_list if x.strip('.') not in ignored)
def find_command(cmd, path=None, pathext=None):
if path is None:
@@ -161,7 +161,7 @@ def get_validation_errors(outfile, app=None):
for rel_field in f.foreign_related_fields:
has_unique_field = has_unique_field or rel_field.unique
if not has_unique_field:
- e.add(opts, "Field combination '%s' under model '%s' must have a unique=True constraint" % (','.join([rel_field.name for rel_field in f.foreign_related_fields]), f.rel.to.__name__))
+ e.add(opts, "Field combination '%s' under model '%s' must have a unique=True constraint" % (','.join(rel_field.name for rel_field in f.foreign_related_fields), f.rel.to.__name__))
else:
if not f.foreign_related_fields[0].unique:
e.add(opts, "Field '%s' under model '%s' must have a unique=True constraint." % (f.foreign_related_fields[0].name, f.rel.to.__name__))
Oops, something went wrong.

0 comments on commit 11cd738

Please sign in to comment.