mirror of
https://github.com/django/django.git
synced 2025-11-18 19:01:40 +00:00
Fixed #20989 -- Removed useless explicit list comprehensions.
This commit is contained in:
parent
e4a67fd906
commit
11cd7388f7
75 changed files with 163 additions and 163 deletions
|
|
@ -79,7 +79,7 @@ class OracleChecks(unittest.TestCase):
|
|||
# than 4000 chars and read it properly
|
||||
c = connection.cursor()
|
||||
c.execute('CREATE TABLE ltext ("TEXT" NCLOB)')
|
||||
long_str = ''.join([six.text_type(x) for x in xrange(4000)])
|
||||
long_str = ''.join(six.text_type(x) for x in xrange(4000))
|
||||
c.execute('INSERT INTO ltext VALUES (%s)', [long_str])
|
||||
c.execute('SELECT text FROM ltext')
|
||||
row = c.fetchone()
|
||||
|
|
|
|||
|
|
@ -89,14 +89,14 @@ def file_upload_echo(request):
|
|||
"""
|
||||
Simple view to echo back info about uploaded files for tests.
|
||||
"""
|
||||
r = dict([(k, f.name) for k, f in request.FILES.items()])
|
||||
r = dict((k, f.name) for k, f in request.FILES.items())
|
||||
return HttpResponse(json.dumps(r))
|
||||
|
||||
def file_upload_echo_content(request):
|
||||
"""
|
||||
Simple view to echo back the content of uploaded files for tests.
|
||||
"""
|
||||
r = dict([(k, f.read().decode('utf-8')) for k, f in request.FILES.items()])
|
||||
r = dict((k, f.read().decode('utf-8')) for k, f in request.FILES.items())
|
||||
return HttpResponse(json.dumps(r))
|
||||
|
||||
def file_upload_quota(request):
|
||||
|
|
|
|||
|
|
@ -221,7 +221,7 @@ class FormsErrorMessagesTestCase(TestCase, AssertFormErrorsMixin):
|
|||
|
||||
def as_divs(self):
|
||||
if not self: return ''
|
||||
return mark_safe('<div class="error">%s</div>' % ''.join(['<p>%s</p>' % e for e in self]))
|
||||
return mark_safe('<div class="error">%s</div>' % ''.join('<p>%s</p>' % e for e in self))
|
||||
|
||||
# This form should print errors the default way.
|
||||
form1 = TestForm({'first_name': 'John'})
|
||||
|
|
|
|||
|
|
@ -723,7 +723,7 @@ class FormsExtraTestCase(TestCase, AssertFormErrorsMixin):
|
|||
|
||||
def as_divs(self):
|
||||
if not self: return ''
|
||||
return '<div class="errorlist">%s</div>' % ''.join(['<div class="error">%s</div>' % force_text(e) for e in self])
|
||||
return '<div class="errorlist">%s</div>' % ''.join('<div class="error">%s</div>' % force_text(e) for e in self)
|
||||
|
||||
class CommentForm(Form):
|
||||
name = CharField(max_length=50, required=False)
|
||||
|
|
|
|||
|
|
@ -437,11 +437,11 @@ class FormsTestCase(TestCase):
|
|||
name = ChoiceField(choices=[('john', 'John'), ('paul', 'Paul'), ('george', 'George'), ('ringo', 'Ringo')], widget=RadioSelect)
|
||||
|
||||
f = BeatleForm(auto_id=False)
|
||||
self.assertHTMLEqual('\n'.join([str(bf) for bf in f['name']]), """<label><input type="radio" name="name" value="john" /> John</label>
|
||||
self.assertHTMLEqual('\n'.join(str(bf) for bf in f['name']), """<label><input type="radio" name="name" value="john" /> John</label>
|
||||
<label><input type="radio" name="name" value="paul" /> Paul</label>
|
||||
<label><input type="radio" name="name" value="george" /> George</label>
|
||||
<label><input type="radio" name="name" value="ringo" /> Ringo</label>""")
|
||||
self.assertHTMLEqual('\n'.join(['<div>%s</div>' % bf for bf in f['name']]), """<div><label><input type="radio" name="name" value="john" /> John</label></div>
|
||||
self.assertHTMLEqual('\n'.join('<div>%s</div>' % bf for bf in f['name']), """<div><label><input type="radio" name="name" value="john" /> John</label></div>
|
||||
<div><label><input type="radio" name="name" value="paul" /> Paul</label></div>
|
||||
<div><label><input type="radio" name="name" value="george" /> George</label></div>
|
||||
<div><label><input type="radio" name="name" value="ringo" /> Ringo</label></div>""")
|
||||
|
|
@ -452,7 +452,7 @@ class FormsTestCase(TestCase):
|
|||
name = CharField()
|
||||
|
||||
f = BeatleForm(auto_id=False)
|
||||
self.assertHTMLEqual('\n'.join([str(bf) for bf in f['name']]), '<input type="text" name="name" />')
|
||||
self.assertHTMLEqual('\n'.join(str(bf) for bf in f['name']), '<input type="text" name="name" />')
|
||||
|
||||
def test_forms_with_multiple_choice(self):
|
||||
# MultipleChoiceField is a special case, as its data is required to be a list:
|
||||
|
|
|
|||
|
|
@ -900,7 +900,7 @@ class FormsFormsetTestCase(TestCase):
|
|||
}
|
||||
formset = AnotherChoiceFormSet(data, auto_id=False, prefix='choices')
|
||||
self.assertTrue(formset.is_valid())
|
||||
self.assertTrue(all([form.is_valid_called for form in formset.forms]))
|
||||
self.assertTrue(all(form.is_valid_called for form in formset.forms))
|
||||
|
||||
def test_hard_limit_on_instantiated_forms(self):
|
||||
"""A formset has a hard limit on the number of forms instantiated."""
|
||||
|
|
|
|||
|
|
@ -640,7 +640,7 @@ beatle J R Ringo False""")
|
|||
# You can create your own custom renderers for RadioSelect to use.
|
||||
class MyRenderer(RadioFieldRenderer):
|
||||
def render(self):
|
||||
return '<br />\n'.join([six.text_type(choice) for choice in self])
|
||||
return '<br />\n'.join(six.text_type(choice) for choice in self)
|
||||
w = RadioSelect(renderer=MyRenderer)
|
||||
self.assertHTMLEqual(w.render('beatle', 'G', choices=(('J', 'John'), ('P', 'Paul'), ('G', 'George'), ('R', 'Ringo'))), """<label><input type="radio" name="beatle" value="J" /> John</label><br />
|
||||
<label><input type="radio" name="beatle" value="P" /> Paul</label><br />
|
||||
|
|
@ -835,17 +835,17 @@ beatle J R Ringo False""")
|
|||
|
||||
def test_subwidget(self):
|
||||
# Each subwidget tag gets a separate ID when the widget has an ID specified
|
||||
self.assertHTMLEqual("\n".join([c.tag() for c in CheckboxSelectMultiple(attrs={'id': 'abc'}).subwidgets('letters', list('ac'), choices=zip(list('abc'), list('ABC')))]), """<input checked="checked" type="checkbox" name="letters" value="a" id="abc_0" />
|
||||
self.assertHTMLEqual("\n".join(c.tag() for c in CheckboxSelectMultiple(attrs={'id': 'abc'}).subwidgets('letters', list('ac'), choices=zip(list('abc'), list('ABC')))), """<input checked="checked" type="checkbox" name="letters" value="a" id="abc_0" />
|
||||
<input type="checkbox" name="letters" value="b" id="abc_1" />
|
||||
<input checked="checked" type="checkbox" name="letters" value="c" id="abc_2" />""")
|
||||
|
||||
# Each subwidget tag does not get an ID if the widget does not have an ID specified
|
||||
self.assertHTMLEqual("\n".join([c.tag() for c in CheckboxSelectMultiple().subwidgets('letters', list('ac'), choices=zip(list('abc'), list('ABC')))]), """<input checked="checked" type="checkbox" name="letters" value="a" />
|
||||
self.assertHTMLEqual("\n".join(c.tag() for c in CheckboxSelectMultiple().subwidgets('letters', list('ac'), choices=zip(list('abc'), list('ABC')))), """<input checked="checked" type="checkbox" name="letters" value="a" />
|
||||
<input type="checkbox" name="letters" value="b" />
|
||||
<input checked="checked" type="checkbox" name="letters" value="c" />""")
|
||||
|
||||
# The id_for_label property of the subwidget should return the ID that is used on the subwidget's tag
|
||||
self.assertHTMLEqual("\n".join(['<input type="checkbox" name="letters" value="%s" id="%s" />' % (c.choice_value, c.id_for_label) for c in CheckboxSelectMultiple(attrs={'id': 'abc'}).subwidgets('letters', [], choices=zip(list('abc'), list('ABC')))]), """<input type="checkbox" name="letters" value="a" id="abc_0" />
|
||||
self.assertHTMLEqual("\n".join('<input type="checkbox" name="letters" value="%s" id="%s" />' % (c.choice_value, c.id_for_label) for c in CheckboxSelectMultiple(attrs={'id': 'abc'}).subwidgets('letters', [], choices=zip(list('abc'), list('ABC')))), """<input type="checkbox" name="letters" value="a" id="abc_0" />
|
||||
<input type="checkbox" name="letters" value="b" id="abc_1" />
|
||||
<input type="checkbox" name="letters" value="c" id="abc_2" />""")
|
||||
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ class ProxyModelTests(TestCase):
|
|||
Person.objects.create(name="Foo McBar")
|
||||
MyPerson.objects.create(name="Bazza del Frob")
|
||||
LowerStatusPerson.objects.create(status="low", name="homer")
|
||||
pp = sorted([mpp.name for mpp in MyPersonProxy.objects.all()])
|
||||
pp = sorted(mpp.name for mpp in MyPersonProxy.objects.all())
|
||||
self.assertEqual(pp, ['Bazza del Frob', 'Foo McBar', 'homer'])
|
||||
|
||||
def test_proxy_included_in_ancestors(self):
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class SchemaTests(TransactionTestCase):
|
|||
"table": connection.ops.quote_name(field.rel.through._meta.db_table),
|
||||
})
|
||||
except DatabaseError as e:
|
||||
if any([s in str(e).lower() for s in self.no_table_strings]):
|
||||
if any(s in str(e).lower() for s in self.no_table_strings):
|
||||
pass
|
||||
else:
|
||||
raise
|
||||
|
|
@ -53,7 +53,7 @@ class SchemaTests(TransactionTestCase):
|
|||
"table": connection.ops.quote_name(model._meta.db_table),
|
||||
})
|
||||
except DatabaseError as e:
|
||||
if any([s in str(e).lower() for s in self.no_table_strings]):
|
||||
if any(s in str(e).lower() for s in self.no_table_strings):
|
||||
pass
|
||||
else:
|
||||
raise
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ def example_view(request):
|
|||
|
||||
def model_view(request):
|
||||
people = Person.objects.all()
|
||||
return HttpResponse('\n'.join([person.name for person in people]))
|
||||
return HttpResponse('\n'.join(person.name for person in people))
|
||||
|
||||
|
||||
def create_model_instance(request):
|
||||
|
|
@ -18,4 +18,4 @@ def create_model_instance(request):
|
|||
|
||||
|
||||
def environ_view(request):
|
||||
return HttpResponse("\n".join(["%s: %r" % (k, v) for k, v in request.environ.items()]))
|
||||
return HttpResponse("\n".join("%s: %r" % (k, v) for k, v in request.environ.items()))
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ class FeedTestCase(TestCase):
|
|||
fixtures = ['feeddata.json']
|
||||
|
||||
def assertChildNodes(self, elem, expected):
|
||||
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)
|
||||
|
||||
|
|
|
|||
|
|
@ -64,13 +64,13 @@ simple_one_default.anything = "Expected simple_one_default __dict__"
|
|||
@register.simple_tag
|
||||
def simple_unlimited_args(one, two='hi', *args):
|
||||
"""Expected simple_unlimited_args __doc__"""
|
||||
return "simple_unlimited_args - Expected result: %s" % (', '.join([six.text_type(arg) for arg in [one, two] + list(args)]))
|
||||
return "simple_unlimited_args - Expected result: %s" % (', '.join(six.text_type(arg) for arg in [one, two] + list(args)))
|
||||
simple_unlimited_args.anything = "Expected simple_unlimited_args __dict__"
|
||||
|
||||
@register.simple_tag
|
||||
def simple_only_unlimited_args(*args):
|
||||
"""Expected simple_only_unlimited_args __doc__"""
|
||||
return "simple_only_unlimited_args - Expected result: %s" % ', '.join([six.text_type(arg) for arg in args])
|
||||
return "simple_only_unlimited_args - Expected result: %s" % ', '.join(six.text_type(arg) for arg in args)
|
||||
simple_only_unlimited_args.anything = "Expected simple_only_unlimited_args __dict__"
|
||||
|
||||
@register.simple_tag
|
||||
|
|
@ -79,8 +79,8 @@ def simple_unlimited_args_kwargs(one, two='hi', *args, **kwargs):
|
|||
# Sort the dictionary by key to guarantee the order for testing.
|
||||
sorted_kwarg = sorted(six.iteritems(kwargs), key=operator.itemgetter(0))
|
||||
return "simple_unlimited_args_kwargs - Expected result: %s / %s" % (
|
||||
', '.join([six.text_type(arg) for arg in [one, two] + list(args)]),
|
||||
', '.join(['%s=%s' % (k, v) for (k, v) in sorted_kwarg])
|
||||
', '.join(six.text_type(arg) for arg in [one, two] + list(args)),
|
||||
', '.join('%s=%s' % (k, v) for (k, v) in sorted_kwarg)
|
||||
)
|
||||
simple_unlimited_args_kwargs.anything = "Expected simple_unlimited_args_kwargs __dict__"
|
||||
|
||||
|
|
@ -191,25 +191,25 @@ inclusion_one_default_from_template.anything = "Expected inclusion_one_default_f
|
|||
@register.inclusion_tag('inclusion.html')
|
||||
def inclusion_unlimited_args(one, two='hi', *args):
|
||||
"""Expected inclusion_unlimited_args __doc__"""
|
||||
return {"result": "inclusion_unlimited_args - Expected result: %s" % (', '.join([six.text_type(arg) for arg in [one, two] + list(args)]))}
|
||||
return {"result": "inclusion_unlimited_args - Expected result: %s" % (', '.join(six.text_type(arg) for arg in [one, two] + list(args)))}
|
||||
inclusion_unlimited_args.anything = "Expected inclusion_unlimited_args __dict__"
|
||||
|
||||
@register.inclusion_tag(get_template('inclusion.html'))
|
||||
def inclusion_unlimited_args_from_template(one, two='hi', *args):
|
||||
"""Expected inclusion_unlimited_args_from_template __doc__"""
|
||||
return {"result": "inclusion_unlimited_args_from_template - Expected result: %s" % (', '.join([six.text_type(arg) for arg in [one, two] + list(args)]))}
|
||||
return {"result": "inclusion_unlimited_args_from_template - Expected result: %s" % (', '.join(six.text_type(arg) for arg in [one, two] + list(args)))}
|
||||
inclusion_unlimited_args_from_template.anything = "Expected inclusion_unlimited_args_from_template __dict__"
|
||||
|
||||
@register.inclusion_tag('inclusion.html')
|
||||
def inclusion_only_unlimited_args(*args):
|
||||
"""Expected inclusion_only_unlimited_args __doc__"""
|
||||
return {"result": "inclusion_only_unlimited_args - Expected result: %s" % (', '.join([six.text_type(arg) for arg in args]))}
|
||||
return {"result": "inclusion_only_unlimited_args - Expected result: %s" % (', '.join(six.text_type(arg) for arg in args))}
|
||||
inclusion_only_unlimited_args.anything = "Expected inclusion_only_unlimited_args __dict__"
|
||||
|
||||
@register.inclusion_tag(get_template('inclusion.html'))
|
||||
def inclusion_only_unlimited_args_from_template(*args):
|
||||
"""Expected inclusion_only_unlimited_args_from_template __doc__"""
|
||||
return {"result": "inclusion_only_unlimited_args_from_template - Expected result: %s" % (', '.join([six.text_type(arg) for arg in args]))}
|
||||
return {"result": "inclusion_only_unlimited_args_from_template - Expected result: %s" % (', '.join(six.text_type(arg) for arg in args))}
|
||||
inclusion_only_unlimited_args_from_template.anything = "Expected inclusion_only_unlimited_args_from_template __dict__"
|
||||
|
||||
@register.inclusion_tag('test_incl_tag_current_app.html', takes_context=True)
|
||||
|
|
@ -230,8 +230,8 @@ def inclusion_unlimited_args_kwargs(one, two='hi', *args, **kwargs):
|
|||
# Sort the dictionary by key to guarantee the order for testing.
|
||||
sorted_kwarg = sorted(six.iteritems(kwargs), key=operator.itemgetter(0))
|
||||
return {"result": "inclusion_unlimited_args_kwargs - Expected result: %s / %s" % (
|
||||
', '.join([six.text_type(arg) for arg in [one, two] + list(args)]),
|
||||
', '.join(['%s=%s' % (k, v) for (k, v) in sorted_kwarg])
|
||||
', '.join(six.text_type(arg) for arg in [one, two] + list(args)),
|
||||
', '.join('%s=%s' % (k, v) for (k, v) in sorted_kwarg)
|
||||
)}
|
||||
inclusion_unlimited_args_kwargs.anything = "Expected inclusion_unlimited_args_kwargs __dict__"
|
||||
|
||||
|
|
@ -286,13 +286,13 @@ assignment_one_default.anything = "Expected assignment_one_default __dict__"
|
|||
@register.assignment_tag
|
||||
def assignment_unlimited_args(one, two='hi', *args):
|
||||
"""Expected assignment_unlimited_args __doc__"""
|
||||
return "assignment_unlimited_args - Expected result: %s" % (', '.join([six.text_type(arg) for arg in [one, two] + list(args)]))
|
||||
return "assignment_unlimited_args - Expected result: %s" % (', '.join(six.text_type(arg) for arg in [one, two] + list(args)))
|
||||
assignment_unlimited_args.anything = "Expected assignment_unlimited_args __dict__"
|
||||
|
||||
@register.assignment_tag
|
||||
def assignment_only_unlimited_args(*args):
|
||||
"""Expected assignment_only_unlimited_args __doc__"""
|
||||
return "assignment_only_unlimited_args - Expected result: %s" % ', '.join([six.text_type(arg) for arg in args])
|
||||
return "assignment_only_unlimited_args - Expected result: %s" % ', '.join(six.text_type(arg) for arg in args)
|
||||
assignment_only_unlimited_args.anything = "Expected assignment_only_unlimited_args __dict__"
|
||||
|
||||
@register.assignment_tag
|
||||
|
|
@ -301,8 +301,8 @@ def assignment_unlimited_args_kwargs(one, two='hi', *args, **kwargs):
|
|||
# Sort the dictionary by key to guarantee the order for testing.
|
||||
sorted_kwarg = sorted(six.iteritems(kwargs), key=operator.itemgetter(0))
|
||||
return "assignment_unlimited_args_kwargs - Expected result: %s / %s" % (
|
||||
', '.join([six.text_type(arg) for arg in [one, two] + list(args)]),
|
||||
', '.join(['%s=%s' % (k, v) for (k, v) in sorted_kwarg])
|
||||
', '.join(six.text_type(arg) for arg in [one, two] + list(args)),
|
||||
', '.join('%s=%s' % (k, v) for (k, v) in sorted_kwarg)
|
||||
)
|
||||
assignment_unlimited_args_kwargs.anything = "Expected assignment_unlimited_args_kwargs __dict__"
|
||||
|
||||
|
|
|
|||
|
|
@ -507,7 +507,7 @@ class TemplateTests(TransRealMixin, TestCase):
|
|||
template_tests.update(filter_tests)
|
||||
|
||||
cache_loader = setup_test_template_loader(
|
||||
dict([(name, t[0]) for name, t in six.iteritems(template_tests)]),
|
||||
dict((name, t[0]) for name, t in six.iteritems(template_tests)),
|
||||
use_cached_loader=True,
|
||||
)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue