From 080359c4c5242ef69ac8c58c92f240e71121ffd7 Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Sun, 31 Jul 2022 07:48:52 +0200 Subject: [PATCH] [4.0.x] Fixed warnings per flake8 5.0.0. Backport of c18861804feb6a97afbeabb51be748dd60a04458 from main. --- .pre-commit-config.yaml | 2 +- .../commands/remove_stale_contenttypes.py | 24 ++--- tests/admin_views/tests.py | 5 +- tests/forms_tests/tests/test_forms.py | 41 ++++--- tests/forms_tests/tests/test_formsets.py | 101 ++++++++++-------- tests/model_forms/tests.py | 88 +++++++-------- 6 files changed, 142 insertions(+), 119 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 494c266f76..3b08b5a998 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,7 +8,7 @@ repos: hooks: - id: isort - repo: https://github.com/PyCQA/flake8 - rev: 3.9.2 + rev: 5.0.0 hooks: - id: flake8 - repo: https://github.com/pre-commit/mirrors-eslint diff --git a/django/contrib/contenttypes/management/commands/remove_stale_contenttypes.py b/django/contrib/contenttypes/management/commands/remove_stale_contenttypes.py index aa42d0192f..edddaa29a4 100644 --- a/django/contrib/contenttypes/management/commands/remove_stale_contenttypes.py +++ b/django/contrib/contenttypes/management/commands/remove_stale_contenttypes.py @@ -72,18 +72,18 @@ class Command(BaseCommand): ) content_type_display = "\n".join(ct_info) self.stdout.write( - """Some content types in your database are stale and can be deleted. -Any objects that depend on these content types will also be deleted. -The content types and dependent objects that would be deleted are: - -%s - -This list doesn't include any cascade deletions to data outside of Django's -models (uncommon). - -Are you sure you want to delete these content types? -If you're unsure, answer 'no'.""" - % content_type_display + "Some content types in your database are stale and can be " + "deleted.\n" + "Any objects that depend on these content types will also be " + "deleted.\n" + "The content types and dependent objects that would be deleted " + "are:\n\n" + f"{content_type_display}\n\n" + "This list doesn't include any cascade deletions to data " + "outside of Django's\n" + "models (uncommon).\n\n" + "Are you sure you want to delete these content types?\n" + "If you're unsure, answer 'no'." ) ok_to_delete = input("Type 'yes' to continue, or 'no' to cancel: ") else: diff --git a/tests/admin_views/tests.py b/tests/admin_views/tests.py index e7ff999b5d..e59bf7adb9 100644 --- a/tests/admin_views/tests.py +++ b/tests/admin_views/tests.py @@ -800,8 +800,9 @@ class AdminViewBasicTest(AdminViewBasicTestCase): self.assertIs(response.context["cl"].has_related_field_in_list_display(), False) def test_limited_filter(self): - """Ensure admin changelist filters do not contain objects excluded via limit_choices_to. - This also tests relation-spanning filters (e.g. 'color__value'). + """ + Admin changelist filters do not contain objects excluded via + limit_choices_to. """ response = self.client.get(reverse("admin:admin_views_thing_changelist")) self.assertContains( diff --git a/tests/forms_tests/tests/test_forms.py b/tests/forms_tests/tests/test_forms.py index 1972d34685..d1b5f8468d 100644 --- a/tests/forms_tests/tests/test_forms.py +++ b/tests/forms_tests/tests/test_forms.py @@ -129,9 +129,12 @@ class FormsTestCase(SimpleTestCase): self.assertHTMLEqual( "\n".join(form_output), - """ - -""", + '" + '" + '", ) form_output = [] @@ -828,10 +831,12 @@ class FormsTestCase(SimpleTestCase): f = BeatleForm(auto_id=False) self.assertHTMLEqual( "\n".join(str(bf) for bf in f["name"]), - """ - - -""", + '' + '' + '" + '", ) self.assertHTMLEqual( "\n".join("
%s
" % bf for bf in f["name"]), @@ -2034,8 +2039,10 @@ class FormsTestCase(SimpleTestCase): p = UserRegistration(auto_id=False) self.assertHTMLEqual( p.as_ul(), - """
  • Username:
  • -
  • Password:
  • """, + '
  • Username: ' + "
  • " + '
  • Password:
  • ", ) def test_specifying_labels(self): @@ -2125,8 +2132,9 @@ class FormsTestCase(SimpleTestCase): p = UserRegistration(auto_id=False) self.assertHTMLEqual( p.as_ul(), - """
  • Username:
  • -
  • Password:
  • """, + '
  • Username: ' + "
  • " + '
  • Password:
  • ', ) p = UserRegistration(auto_id="id_%s") self.assertHTMLEqual( @@ -2743,11 +2751,12 @@ Options: -e.g., user@example.com -
  • -Password: -Wählen Sie mit Bedacht.
  • """, + '
  • Username: ' + 'e.g., user@example.com
  • ' + '
  • ' + 'Password: ' + 'Wählen Sie mit Bedacht.
  • ', ) # help_text is not displayed for hidden fields. It can be used for documentation diff --git a/tests/forms_tests/tests/test_formsets.py b/tests/forms_tests/tests/test_formsets.py index 31abbdf9f8..0ae0bb18cf 100644 --- a/tests/forms_tests/tests/test_formsets.py +++ b/tests/forms_tests/tests/test_formsets.py @@ -227,10 +227,11 @@ class FormsFormsetTestCase(SimpleTestCase): ) self.assertHTMLEqual( "\n".join(form.as_ul() for form in formset.forms), - """
  • Choice:
  • -
  • Votes:
  • -
  • Choice:
  • -
  • Votes:
  • """, + '
  • Choice: ' + "
  • " + '
  • Votes:
  • ' + '
  • Choice:
  • ' + '
  • Votes:
  • ', ) def test_blank_form_unfilled(self): @@ -484,14 +485,15 @@ class FormsFormsetTestCase(SimpleTestCase): formset = ChoiceFormSet(initial=initial, auto_id=False, prefix="choices") self.assertHTMLEqual( "\n".join(form.as_ul() for form in formset.forms), - """
  • Choice:
  • -
  • Votes:
  • -
  • Choice:
  • -
  • Votes:
  • -
  • Choice:
  • -
  • Votes:
  • -
  • Choice:
  • -
  • Votes:
  • """, + '
  • Choice: ' + "
  • " + '
  • Votes:
  • ' + '
  • Choice:
  • ' + '
  • Votes:
  • ' + '
  • Choice:
  • ' + '
  • Votes:
  • ' + '
  • Choice:
  • ' + '
  • Votes:
  • ', ) # Retrieving an empty form works. Tt shows up in the form list. self.assertTrue(formset.empty_form.empty_permitted) @@ -515,15 +517,17 @@ class FormsFormsetTestCase(SimpleTestCase): formset = ChoiceFormSet(initial=initial, auto_id=False, prefix="choices") self.assertHTMLEqual( "\n".join(form.as_ul() for form in formset.forms), - """
  • Choice:
  • -
  • Votes:
  • -
  • Delete:
  • -
  • Choice:
  • -
  • Votes:
  • -
  • Delete:
  • -
  • Choice:
  • -
  • Votes:
  • -
  • Delete:
  • """, + '
  • Choice: ' + "
  • " + '
  • Votes:
  • ' + '
  • Delete:
  • ' + '
  • Choice: ' + "
  • " + '
  • Votes:
  • ' + '
  • Delete:
  • ' + '
  • Choice:
  • ' + '
  • Votes:
  • ' + '
  • Delete:
  • ', ) # To delete something, set that form's special delete field to 'on'. # Let's go ahead and delete Fergie. @@ -658,15 +662,17 @@ class FormsFormsetTestCase(SimpleTestCase): formset = ChoiceFormSet(initial=initial, auto_id=False, prefix="choices") self.assertHTMLEqual( "\n".join(form.as_ul() for form in formset.forms), - """
  • Choice:
  • -
  • Votes:
  • -
  • Order:
  • -
  • Choice:
  • -
  • Votes:
  • -
  • Order:
  • -
  • Choice:
  • -
  • Votes:
  • -
  • Order:
  • """, + '
  • Choice: ' + "
  • " + '
  • Votes:
  • ' + '
  • Order:
  • ' + '
  • Choice: ' + "
  • " + '
  • Votes:
  • ' + '
  • Order:
  • ' + '
  • Choice:
  • ' + '
  • Votes:
  • ' + '
  • Order:
  • ', ) data = { "choices-TOTAL_FORMS": "3", # the number of forms rendered @@ -784,22 +790,25 @@ class FormsFormsetTestCase(SimpleTestCase): formset = ChoiceFormSet(initial=initial, auto_id=False, prefix="choices") self.assertHTMLEqual( "\n".join(form.as_ul() for form in formset.forms), - """
  • Choice:
  • -
  • Votes:
  • -
  • Order:
  • -
  • Delete:
  • -
  • Choice:
  • -
  • Votes:
  • -
  • Order:
  • -
  • Delete:
  • -
  • Choice:
  • -
  • Votes:
  • -
  • Order:
  • -
  • Delete:
  • -
  • Choice:
  • -
  • Votes:
  • -
  • Order:
  • -
  • Delete:
  • """, + '
  • Choice: ' + "
  • " + '
  • Votes:
  • ' + '
  • Order:
  • ' + '
  • Delete:
  • ' + '
  • Choice: ' + "
  • " + '
  • Votes:
  • ' + '
  • Order:
  • ' + '
  • Delete:
  • ' + '
  • Choice:
  • ' + '
  • Votes:
  • ' + '
  • Order:
  • ' + '
  • Delete:
  • ' + '
  • Choice:
  • ' + '
  • Votes:
  • ' + '
  • Order:
  • ' + '
  • Delete:
  • ', ) # Let's delete Fergie, and put The Decemberists ahead of Calexico. data = { diff --git a/tests/model_forms/tests.py b/tests/model_forms/tests.py index a615d4516d..1b024f5d18 100644 --- a/tests/model_forms/tests.py +++ b/tests/model_forms/tests.py @@ -1916,26 +1916,28 @@ class ModelFormBasicTests(TestCase): f = ArticleForm(auto_id=False) self.assertHTMLEqual( f.as_ul(), - """
  • Headline:
  • -
  • Slug:
  • -
  • Pub date:
  • -
  • Writer:
  • -
  • Article:
  • -
  • Categories:
  • -
  • Status:
  • """ + '
  • Headline: ' + "
  • " + '
  • Slug:
  • ' + '
  • Pub date:
  • ' + '
  • Writer:
  • " + '
  • Article:
  • " + '
  • Categories:
  • " + '
  • Status:
  • " % (self.w_woodward.pk, self.w_royko.pk, self.c1.pk, self.c2.pk, self.c3.pk), ) @@ -1943,28 +1945,30 @@ class ModelFormBasicTests(TestCase): w_bernstein = Writer.objects.create(name="Carl Bernstein") self.assertHTMLEqual( f.as_ul(), - """
  • Headline:
  • -
  • Slug:
  • -
  • Pub date:
  • -
  • Writer:
  • -
  • Article:
  • -
  • Categories:
  • -
  • Status:
  • """ + '
  • Headline: ' + "
  • " + '
  • Slug:
  • ' + '
  • Pub date:
  • ' + '
  • Writer:
  • " + '
  • Article:
  • " + '
  • Categories:
  • " + '
  • Status:
  • " % ( self.w_woodward.pk, w_bernstein.pk,