Jelajahi Sumber

Fix linting failures for flake8 3.6

Matt Westcott 6 tahun lalu
induk
melakukan
33e290b82d
38 mengubah file dengan 99 tambahan dan 125 penghapusan
  1. 1 1
      setup.cfg
  2. 1 1
      setup.py
  3. 2 1
      tox.ini
  4. 0 2
      wagtail/admin/tests/api/test_documents.py
  5. 0 2
      wagtail/admin/tests/api/test_images.py
  6. 0 2
      wagtail/admin/tests/api/test_pages.py
  7. 4 4
      wagtail/admin/views/generic.py
  8. 7 7
      wagtail/admin/views/pages.py
  9. 5 5
      wagtail/admin/widgets.py
  10. 0 7
      wagtail/api/v2/tests/test_documents.py
  11. 0 7
      wagtail/api/v2/tests/test_images.py
  12. 0 8
      wagtail/api/v2/tests/test_pages.py
  13. 0 2
      wagtail/api/v2/tests/tests.py
  14. 2 2
      wagtail/contrib/modeladmin/options.py
  15. 4 4
      wagtail/contrib/postgres_search/backend.py
  16. 3 3
      wagtail/contrib/redirects/views.py
  17. 1 1
      wagtail/contrib/routable_page/templatetags/wagtailroutablepage_tags.py
  18. 2 2
      wagtail/contrib/search_promotions/forms.py
  19. 3 3
      wagtail/contrib/search_promotions/wagtail_hooks.py
  20. 1 1
      wagtail/core/blocks/utils.py
  21. 2 2
      wagtail/core/management/commands/replace_text.py
  22. 8 8
      wagtail/core/models.py
  23. 7 7
      wagtail/core/permission_policies/base.py
  24. 2 2
      wagtail/core/permission_policies/collections.py
  25. 1 1
      wagtail/core/tests/test_blocks.py
  26. 1 1
      wagtail/core/whitelist.py
  27. 4 1
      wagtail/documents/tests/test_admin_views.py
  28. 1 1
      wagtail/images/templatetags/wagtailimages_tags.py
  29. 4 4
      wagtail/images/tests/test_admin_views.py
  30. 2 2
      wagtail/images/tests/tests.py
  31. 2 2
      wagtail/images/views/chooser.py
  32. 8 8
      wagtail/search/backends/base.py
  33. 2 2
      wagtail/search/backends/db.py
  34. 2 2
      wagtail/search/backends/elasticsearch2.py
  35. 6 5
      wagtail/search/tests/test_backends.py
  36. 2 2
      wagtail/snippets/views/snippets.py
  37. 0 1
      wagtail/tests/dummy_external_storage.py
  38. 9 9
      wagtail/users/wagtail_hooks.py

+ 1 - 1
setup.cfg

@@ -2,7 +2,7 @@
 python-tag = py3
 
 [flake8]
-ignore = E501,E303
+ignore = E501,E303,W503
 exclude = wagtail/project_template/*,wagtail/utils/l18n/*
 max-line-length = 120
 

+ 1 - 1
setup.py

@@ -50,7 +50,7 @@ testing_extras = [
 
     # For coverage and PEP8 linting
     'coverage>=3.7.0',
-    'flake8>=2.2.0',
+    'flake8>=3.6.0',
     'isort==4.2.5',
     'flake8-blind-except==0.1.1',
     'flake8-print==2.0.2',

+ 2 - 1
tox.ini

@@ -19,9 +19,10 @@ envlist = py{34,35,36,37}-dj{20,21,master}-{sqlite,postgres,mysql,mssql}-{elasti
 # D401: First line should be in imperative mood
 # E303: Too many blank lines
 # E501: Line too long
+# W503: line break before binary operator (superseded by W504 line break after binary operator)
 # N805: First argument of a method should be named 'self'
 # N806: Variable in function should be lowercase
-ignore = D100,D101,D102,D103,D105,D200,D202,D204,D205,D209,D400,D401,E303,E501,N805,N806
+ignore = D100,D101,D102,D103,D105,D200,D202,D204,D205,D209,D400,D401,E303,E501,W503,N805,N806
 
 [testenv]
 install_command = pip install -e ".[testing]" -U {opts} {packages}

+ 0 - 2
wagtail/admin/tests/api/test_documents.py

@@ -17,7 +17,6 @@ class TestAdminDocumentListing(AdminAPITestCase, TestDocumentListing):
     def get_document_id_list(self, content):
         return [document['id'] for document in content['items']]
 
-
     # BASIC TESTS
 
     def test_basic(self):
@@ -57,7 +56,6 @@ class TestAdminDocumentListing(AdminAPITestCase, TestDocumentListing):
             # Check download_url
             self.assertTrue(document['meta']['download_url'].startswith('http://localhost/documents/%d/' % document['id']))
 
-
     # FIELDS
 
     def test_fields_default(self):

+ 0 - 2
wagtail/admin/tests/api/test_images.py

@@ -18,7 +18,6 @@ class TestAdminImageListing(AdminAPITestCase, TestImageListing):
     def get_image_id_list(self, content):
         return [image['id'] for image in content['items']]
 
-
     # BASIC TESTS
 
     def test_basic(self):
@@ -55,7 +54,6 @@ class TestAdminImageListing(AdminAPITestCase, TestImageListing):
             # Check detail url
             self.assertEqual(image['meta']['detail_url'], 'http://localhost/admin/api/v2beta/images/%d/' % image['id'])
 
-
     #  FIELDS
 
     def test_fields_default(self):

+ 0 - 2
wagtail/admin/tests/api/test_pages.py

@@ -27,7 +27,6 @@ class TestAdminPageListing(AdminAPITestCase, TestPageListing):
     def get_page_id_list(self, content):
         return [page['id'] for page in content['items']]
 
-
     # BASIC TESTS
 
     def test_basic(self):
@@ -298,7 +297,6 @@ class TestAdminPageListing(AdminAPITestCase, TestPageListing):
 
         self.assertEqual(response.status_code, 200)
 
-
     # FOR EXPLORER FILTER
 
     def make_simple_page(self, parent, title):

+ 4 - 4
wagtail/admin/views/generic.py

@@ -57,8 +57,8 @@ class IndexView(PermissionCheckedMixin, TemplateResponseMixin, BaseListView):
     def get_context_data(self, **kwargs):
         context = super().get_context_data(**kwargs)
         context['can_add'] = (
-            self.permission_policy is None or
-            self.permission_policy.user_has_permission(self.request.user, 'add')
+            self.permission_policy is None
+            or self.permission_policy.user_has_permission(self.request.user, 'add')
         )
         return context
 
@@ -185,8 +185,8 @@ class EditView(PermissionCheckedMixin, TemplateResponseMixin, BaseUpdateView):
     def get_context_data(self, **kwargs):
         context = super().get_context_data(**kwargs)
         context['can_delete'] = (
-            self.permission_policy is None or
-            self.permission_policy.user_has_permission(self.request.user, 'delete')
+            self.permission_policy is None
+            or self.permission_policy.user_has_permission(self.request.user, 'delete')
         ),
         return context
 

+ 7 - 7
wagtail/admin/views/pages.py

@@ -48,8 +48,8 @@ def index(request, parent_page_id=None):
     # If this page isn't a descendant of the user's explorable root page,
     # then redirect to that explorable root page instead.
     if not (
-        parent_page.pk == root_page.pk or
-        parent_page.is_descendant_of(root_page)
+        parent_page.pk == root_page.pk
+        or parent_page.is_descendant_of(root_page)
     ):
         return redirect('wagtailadmin_explore', root_page.pk)
 
@@ -494,8 +494,8 @@ def edit(request, page_id):
                                                          form=form,
                                                          request=request)
             errors_debug = (
-                repr(edit_handler.form.errors) +
-                repr([
+                repr(edit_handler.form.errors)
+                + repr([
                     (name, formset.errors)
                     for (name, formset) in edit_handler.form.formsets.items()
                     if formset.errors
@@ -731,9 +731,9 @@ def move_choose_destination(request, page_to_move_id, viewed_page_id=None):
         target.can_choose = page_perms.can_move_to(target)
 
         target.can_descend = (
-            not(target == page_to_move or
-                target.is_child_of(page_to_move)) and
-            target.get_children_count()
+            not(target == page_to_move
+                or target.is_child_of(page_to_move))
+            and target.get_children_count()
         )
 
         child_pages.append(target)

+ 5 - 5
wagtail/admin/widgets.py

@@ -264,11 +264,11 @@ class Button:
     def __eq__(self, other):
         if not isinstance(other, Button):
             return NotImplemented
-        return (self.label == other.label and
-                self.url == other.url and
-                self.classes == other.classes and
-                self.attrs == other.attrs and
-                self.priority == other.priority)
+        return (self.label == other.label
+                and self.url == other.url
+                and self.classes == other.classes
+                and self.attrs == other.attrs
+                and self.priority == other.priority)
 
 
 class PageListingButton(Button):

+ 0 - 7
wagtail/api/v2/tests/test_documents.py

@@ -18,7 +18,6 @@ class TestDocumentListing(TestCase):
     def get_document_id_list(self, content):
         return [document['id'] for document in content['items']]
 
-
     # BASIC TESTS
 
     def test_basic(self):
@@ -58,7 +57,6 @@ class TestDocumentListing(TestCase):
             # Check download_url
             self.assertTrue(document['meta']['download_url'].startswith('http://localhost/documents/%d/' % document['id']))
 
-
     # FIELDS
 
     def test_fields_default(self):
@@ -157,7 +155,6 @@ class TestDocumentListing(TestCase):
         self.assertEqual(response.status_code, 400)
         self.assertEqual(content, {'message': "unknown fields: 123, abc"})
 
-
     # FILTERING
 
     def test_filtering_exact_filter(self):
@@ -190,7 +187,6 @@ class TestDocumentListing(TestCase):
         self.assertEqual(response.status_code, 400)
         self.assertEqual(content, {'message': "query parameter is not an operation or a recognised field: not_a_field"})
 
-
     # ORDERING
 
     def test_ordering_by_title(self):
@@ -239,7 +235,6 @@ class TestDocumentListing(TestCase):
         self.assertEqual(response.status_code, 400)
         self.assertEqual(content, {'message': "cannot order by 'not_a_field' (unknown field)"})
 
-
     # LIMIT
 
     def test_limit_only_two_items_returned(self):
@@ -294,7 +289,6 @@ class TestDocumentListing(TestCase):
 
         self.assertEqual(len(content['items']), 2)
 
-
     # OFFSET
 
     def test_offset_5_usually_appears_5th_in_list(self):
@@ -323,7 +317,6 @@ class TestDocumentListing(TestCase):
         self.assertEqual(response.status_code, 400)
         self.assertEqual(content, {'message': "offset must be a positive integer"})
 
-
     # SEARCH
 
     def test_search_for_james_joyce(self):

+ 0 - 7
wagtail/api/v2/tests/test_images.py

@@ -18,7 +18,6 @@ class TestImageListing(TestCase):
     def get_image_id_list(self, content):
         return [image['id'] for image in content['items']]
 
-
     # BASIC TESTS
 
     def test_basic(self):
@@ -55,7 +54,6 @@ class TestImageListing(TestCase):
             # Check detail url
             self.assertEqual(image['meta']['detail_url'], 'http://localhost/api/v2beta/images/%d/' % image['id'])
 
-
     #  FIELDS
 
     def test_fields_default(self):
@@ -157,7 +155,6 @@ class TestImageListing(TestCase):
         self.assertEqual(response.status_code, 400)
         self.assertEqual(content, {'message': "unknown fields: 123, abc"})
 
-
     # FILTERING
 
     def test_filtering_exact_filter(self):
@@ -190,7 +187,6 @@ class TestImageListing(TestCase):
         self.assertEqual(response.status_code, 400)
         self.assertEqual(content, {'message': "query parameter is not an operation or a recognised field: not_a_field"})
 
-
     # ORDERING
 
     def test_ordering_by_title(self):
@@ -239,7 +235,6 @@ class TestImageListing(TestCase):
         self.assertEqual(response.status_code, 400)
         self.assertEqual(content, {'message': "cannot order by 'not_a_field' (unknown field)"})
 
-
     # LIMIT
 
     def test_limit_only_two_items_returned(self):
@@ -294,7 +289,6 @@ class TestImageListing(TestCase):
 
         self.assertEqual(len(content['items']), 2)
 
-
     # OFFSET
 
     def test_offset_10_usually_appears_7th_in_list(self):
@@ -323,7 +317,6 @@ class TestImageListing(TestCase):
         self.assertEqual(response.status_code, 400)
         self.assertEqual(content, {'message': "offset must be a positive integer"})
 
-
     # SEARCH
 
     def test_search_for_james_joyce(self):

+ 0 - 8
wagtail/api/v2/tests/test_pages.py

@@ -27,7 +27,6 @@ class TestPageListing(TestCase):
     def get_page_id_list(self, content):
         return [page['id'] for page in content['items']]
 
-
     # BASIC TESTS
 
     def test_basic(self):
@@ -361,7 +360,6 @@ class TestPageListing(TestCase):
         self.assertEqual(response.status_code, 400)
         self.assertEqual(content, {'message': "'title' does not support nested fields"})
 
-
     # FILTERING
 
     def test_filtering_exact_filter(self):
@@ -434,7 +432,6 @@ class TestPageListing(TestCase):
         self.assertEqual(response.status_code, 400)
         self.assertEqual(content, {'message': "field filter error. 'abc' is not a valid value for show_in_menus (expected 'true' or 'false', got 'abc')"})
 
-
     # CHILD OF FILTER
 
     def test_child_of_filter(self):
@@ -481,7 +478,6 @@ class TestPageListing(TestCase):
         self.assertEqual(response.status_code, 400)
         self.assertEqual(content, {'message': "parent page doesn't exist"})
 
-
     # DESCENDANT OF FILTER
 
     def test_descendant_of_filter(self):
@@ -536,7 +532,6 @@ class TestPageListing(TestCase):
         self.assertEqual(response.status_code, 400)
         self.assertEqual(content, {'message': "filtering by descendant_of with child_of is not supported"})
 
-
     # ORDERING
 
     def test_ordering_default(self):
@@ -613,7 +608,6 @@ class TestPageListing(TestCase):
         self.assertEqual(response.status_code, 400)
         self.assertEqual(content, {'message': "cannot order by 'not_a_field' (unknown field)"})
 
-
     # LIMIT
 
     def test_limit_only_two_items_returned(self):
@@ -668,7 +662,6 @@ class TestPageListing(TestCase):
 
         self.assertEqual(len(content['items']), 2)
 
-
     # OFFSET
 
     def test_offset_5_usually_appears_5th_in_list(self):
@@ -697,7 +690,6 @@ class TestPageListing(TestCase):
         self.assertEqual(response.status_code, 400)
         self.assertEqual(content, {'message': "offset must be a positive integer"})
 
-
     # SEARCH
 
     def test_search_for_blog(self):

+ 0 - 2
wagtail/api/v2/tests/tests.py

@@ -93,7 +93,6 @@ class TestParseFieldsParameter(TestCase):
             ('test_', False, None),
         ])
 
-
     # BAD STUFF
 
     def test_invalid_char(self):
@@ -258,7 +257,6 @@ class TestParseBoolean(TestCase):
 
         self.assertEqual(parsed, False)
 
-
     # BAD STUFF
 
     def test_invalid(self):

+ 2 - 2
wagtail/contrib/modeladmin/options.py

@@ -297,8 +297,8 @@ class ModelAdmin(WagtailRegisterable):
             for f in self.model._meta.get_fields():
                 if f.name not in self.inspect_view_fields_exclude:
                     if f.concrete and (
-                        not f.is_relation or
-                        (not f.auto_created and f.related_model)
+                        not f.is_relation
+                        or (not f.auto_created and f.related_model)
                     ):
                         found_fields.append(f.name)
             return found_fields

+ 4 - 4
wagtail/contrib/postgres_search/backend.py

@@ -330,8 +330,8 @@ class PostgresSearchQueryCompiler(BaseSearchQueryCompiler):
         return queryset[start:stop]
 
     def _process_lookup(self, field, lookup, value):
-        return Q(**{field.get_attname(self.queryset.model) +
-                    '__' + lookup: value})
+        return Q(**{field.get_attname(self.queryset.model)
+                    + '__' + lookup: value})
 
     def _connect_filters(self, filters, connector, negated):
         if connector == 'AND':
@@ -379,8 +379,8 @@ class PostgresSearchResults(BaseSearchResults):
         field = self.query_compiler._get_filterable_field(field_name)
         if field is None:
             raise FilterFieldError(
-                'Cannot facet search results with field "' + field_name + '". Please add index.FilterField(\'' +
-                field_name + '\') to ' + self.query_compiler.queryset.model.__name__ + '.search_fields.',
+                'Cannot facet search results with field "' + field_name + '". Please add index.FilterField(\''
+                + field_name + '\') to ' + self.query_compiler.queryset.model.__name__ + '.search_fields.',
                 field_name=field_name
             )
 

+ 3 - 3
wagtail/contrib/redirects/views.py

@@ -25,9 +25,9 @@ def index(request):
 
     # Search
     if query_string:
-        redirects = redirects.filter(Q(old_path__icontains=query_string) |
-                                     Q(redirect_page__url_path__icontains=query_string) |
-                                     Q(redirect_link__icontains=query_string))
+        redirects = redirects.filter(Q(old_path__icontains=query_string)
+                                     | Q(redirect_page__url_path__icontains=query_string)
+                                     | Q(redirect_link__icontains=query_string))
 
     # Ordering (A bit useless at the moment as only 'old_path' is allowed)
     if ordering not in ['old_path']:

+ 1 - 1
wagtail/contrib/routable_page/templatetags/wagtailroutablepage_tags.py

@@ -7,7 +7,7 @@ register = template.Library()
 def routablepageurl(context, page, url_name, *args, **kwargs):
     """
     ``routablepageurl`` is similar to ``pageurl``, but works with
-    ``RoutablePage``\s. It behaves like a hybrid between the built-in
+    pages using ``RoutablePageMixin``. It behaves like a hybrid between the built-in
     ``reverse``, and ``pageurl`` from Wagtail.
 
     ``page`` is the RoutablePage that URLs will be generated from.

+ 2 - 2
wagtail/contrib/search_promotions/forms.py

@@ -54,7 +54,7 @@ class SearchPromotionsFormSet(SearchPromotionsFormSetBase):
             if not (form.instance.id is None and not form.has_changed()):
                 non_empty_forms += 1
         if (
-            non_deleted_forms < self.minimum_forms or
-            non_empty_forms < self.minimum_forms
+            non_deleted_forms < self.minimum_forms
+            or non_empty_forms < self.minimum_forms
         ):
             raise forms.ValidationError(self.minimum_forms_message)

+ 3 - 3
wagtail/contrib/search_promotions/wagtail_hooks.py

@@ -18,9 +18,9 @@ def register_admin_urls():
 class SearchPicksMenuItem(MenuItem):
     def is_shown(self, request):
         return (
-            request.user.has_perm('wagtailsearchpromotions.add_searchpromotion') or
-            request.user.has_perm('wagtailsearchpromotions.change_searchpromotion') or
-            request.user.has_perm('wagtailsearchpromotions.delete_searchpromotion')
+            request.user.has_perm('wagtailsearchpromotions.add_searchpromotion')
+            or request.user.has_perm('wagtailsearchpromotions.change_searchpromotion')
+            or request.user.has_perm('wagtailsearchpromotions.delete_searchpromotion')
         )
 
 

+ 1 - 1
wagtail/core/blocks/utils.py

@@ -6,7 +6,7 @@ import re
 
 def indent(string, depth=1):
     """indent all non-empty lines of string by 'depth' 4-character tabs"""
-    return re.sub(r'(^|\n)([^\n]+)', '\g<1>' + ('    ' * depth) + '\g<2>', string)
+    return re.sub(r'(^|\n)([^\n]+)', r'\g<1>' + ('    ' * depth) + r'\g<2>', string)
 
 
 def js_dict(d):

+ 2 - 2
wagtail/core/management/commands/replace_text.py

@@ -7,8 +7,8 @@ from wagtail.core.models import PageRevision, get_page_models
 
 def replace_in_model(model, from_text, to_text):
     text_field_names = [field.name for field in model._meta.fields if (
-        isinstance(field, models.TextField) or
-        isinstance(field, models.CharField)
+        isinstance(field, models.TextField)
+        or isinstance(field, models.CharField)
     )
     ]
     updated_fields = []

+ 8 - 8
wagtail/core/models.py

@@ -81,14 +81,14 @@ class Site(models.Model):
     def __str__(self):
         if self.site_name:
             return(
-                self.site_name +
-                (" [default]" if self.is_default_site else "")
+                self.site_name
+                + (" [default]" if self.is_default_site else "")
             )
         else:
             return(
-                self.hostname +
-                ("" if self.port == 80 else (":%d" % self.port)) +
-                (" [default]" if self.is_default_site else "")
+                self.hostname
+                + ("" if self.port == 80 else (":%d" % self.port))
+                + (" [default]" if self.is_default_site else "")
             )
 
     @staticmethod
@@ -1696,9 +1696,9 @@ class PagePermissionTester:
         if self.page_is_root:  # root node is not a page and can never be edited, even by superusers
             return False
         return (
-            self.user.is_superuser or
-            ('edit' in self.permissions) or
-            ('add' in self.permissions and self.page.owner_id == self.user.pk)
+            self.user.is_superuser
+            or ('edit' in self.permissions)
+            or ('add' in self.permissions and self.page.owner_id == self.user.pk)
         )
 
     def can_delete(self):

+ 7 - 7
wagtail/core/permission_policies/base.py

@@ -199,9 +199,9 @@ class BaseDjangoAuthPermissionPolicy(BasePermissionPolicy):
             codename__in=permission_codenames
         )
         return (
-            Q(is_superuser=True) |
-            Q(user_permissions__in=permissions) |
-            Q(groups__permissions__in=permissions)
+            Q(is_superuser=True)
+            | Q(user_permissions__in=permissions)
+            | Q(groups__permissions__in=permissions)
         ) & Q(is_active=True)
 
     def _get_users_with_any_permission_codenames(self, permission_codenames):
@@ -268,8 +268,8 @@ class OwnershipPermissionPolicy(BaseDjangoAuthPermissionPolicy):
                 # having 'add' permission means that there are *potentially*
                 # some instances they can edit (namely: ones they own),
                 # which is sufficient for returning True here
-                user.has_perm(self._get_permission_name('add')) or
-                user.has_perm(self._get_permission_name('change'))
+                user.has_perm(self._get_permission_name('add'))
+                or user.has_perm(self._get_permission_name('change'))
             )
         else:
             # unrecognised actions are only allowed for active superusers
@@ -302,8 +302,8 @@ class OwnershipPermissionPolicy(BaseDjangoAuthPermissionPolicy):
             if user.has_perm(self._get_permission_name('change')):
                 return True
             elif (
-                user.has_perm(self._get_permission_name('add')) and
-                getattr(instance, self.owner_field_name) == user
+                user.has_perm(self._get_permission_name('add'))
+                and getattr(instance, self.owner_field_name) == user
             ):
                 return True
             else:

+ 2 - 2
wagtail/core/permission_policies/collections.py

@@ -255,8 +255,8 @@ class CollectionOwnershipPermissionPolicy(
             if self._check_perm(user, ['change'], collection=instance.collection):
                 return True
             elif (
-                self._check_perm(user, ['add'], collection=instance.collection) and
-                getattr(instance, self.owner_field_name) == user
+                self._check_perm(user, ['add'], collection=instance.collection)
+                and getattr(instance, self.owner_field_name) == user
             ):
                 return True
             else:

+ 1 - 1
wagtail/core/tests/test_blocks.py

@@ -1888,7 +1888,7 @@ class TestStreamBlock(WagtailTestUtils, SimpleTestCase):
 
     def test_initialisation_with_mixins(self):
         """
-        The order of child blocks of ``StreamBlock``\s with multiple parent
+        The order of child blocks of a ``StreamBlock`` with multiple parent
         classes is slightly surprising at first. Child blocks are inherited in
         a bottom-up order, by traversing the MRO in reverse. In the example
         below, ``ArticleWithIntroBlock`` will have an MRO of::

+ 1 - 1
wagtail/core/whitelist.py

@@ -21,7 +21,7 @@ def check_url(url_string):
     unescaped = unescaped.replace("&lt;", "<")
     unescaped = unescaped.replace("&gt;", ">")
     unescaped = unescaped.replace("&amp;", "&")
-    unescaped = re.sub("[`\000-\040\177-\240\s]+", '', unescaped)
+    unescaped = re.sub(r'[`\000-\040\177-\240\s]+', '', unescaped)
     unescaped = unescaped.replace("\ufffd", "")
     if PROTOCOL_RE.match(unescaped):
         protocol = unescaped.split(':', 1)[0]

+ 4 - 1
wagtail/documents/tests/test_admin_views.py

@@ -918,7 +918,10 @@ class TestGetUsage(TestCase, WagtailTestUtils):
         response = self.client.get(reverse('wagtaildocs:document_usage',
                                            args=(1,)))
         # There's no usage so there should be no table rows
-        self.assertRegex(response.content, b'<tbody>(\s|\n)*</tbody>')
+        self.assertRegex(
+            response.content.decode('utf-8'),
+            r'<tbody>(\s|\n)*</tbody>'
+        )
 
 
 class TestEditOnlyPermissions(TestCase, WagtailTestUtils):

+ 1 - 1
wagtail/images/templatetags/wagtailimages_tags.py

@@ -7,7 +7,7 @@ from wagtail.images.models import Filter
 from wagtail.images.shortcuts import get_rendition_or_not_found
 
 register = template.Library()
-allowed_filter_pattern = re.compile("^[A-Za-z0-9_\-\.]+$")
+allowed_filter_pattern = re.compile(r"^[A-Za-z0-9_\-\.]+$")
 
 
 @register.tag(name="image")

+ 4 - 4
wagtail/images/tests/test_admin_views.py

@@ -60,13 +60,13 @@ class TestImageIndexView(TestCase, WagtailTestUtils):
 
         # prev link should exist and include collection_id
         self.assertTrue(
-            ("?p=1&amp;collection_id=%i" % evil_plans_collection.id) in response_body or
-            ("?collection_id=%i&amp;p=1" % evil_plans_collection.id) in response_body
+            ("?p=1&amp;collection_id=%i" % evil_plans_collection.id) in response_body
+            or ("?collection_id=%i&amp;p=1" % evil_plans_collection.id) in response_body
         )
         # next link should exist and include collection_id
         self.assertTrue(
-            ("?p=3&amp;collection_id=%i" % evil_plans_collection.id) in response_body or
-            ("?collection_id=%i&amp;p=3" % evil_plans_collection.id) in response_body
+            ("?p=3&amp;collection_id=%i" % evil_plans_collection.id) in response_body
+            or ("?collection_id=%i&amp;p=3" % evil_plans_collection.id) in response_body
         )
 
     def test_ordering(self):

+ 2 - 2
wagtail/images/tests/tests.py

@@ -54,8 +54,8 @@ class TestImageTag(TestCase):
 
     def render_image_tag_as(self, image, filter_spec):
         temp = template.Template(
-            '{% load wagtailimages_tags %}{% image image_obj ' + filter_spec +
-            ' as test_img %}<img {{ test_img.attrs }} />'
+            '{% load wagtailimages_tags %}{% image image_obj ' + filter_spec
+            + ' as test_img %}<img {{ test_img.attrs }} />'
         )
         context = template.Context({'image_obj': image})
         return temp.render(context)

+ 2 - 2
wagtail/images/views/chooser.py

@@ -79,8 +79,8 @@ def chooser(request):
         images = hook(images, request)
 
     if (
-        'q' in request.GET or 'p' in request.GET or 'tag' in request.GET or
-        'collection_id' in request.GET
+        'q' in request.GET or 'p' in request.GET or 'tag' in request.GET
+        or 'collection_id' in request.GET
     ):
         # this request is triggered from search, pagination or 'popular tags';
         # we will just render the results.html fragment

+ 8 - 8
wagtail/search/backends/base.py

@@ -68,8 +68,8 @@ class BaseSearchQueryCompiler:
 
         if field is None:
             raise FilterFieldError(
-                'Cannot filter search results with field "' + field_attname + '". Please add index.FilterField(\'' +
-                field_attname + '\') to ' + self.queryset.model.__name__ + '.search_fields.',
+                'Cannot filter search results with field "' + field_attname + '". Please add index.FilterField(\''
+                + field_attname + '\') to ' + self.queryset.model.__name__ + '.search_fields.',
                 field_name=field_attname
             )
 
@@ -79,8 +79,8 @@ class BaseSearchQueryCompiler:
 
         if result is None:
             raise FilterError(
-                'Could not apply filter on search results: "' + field_attname + '__' +
-                lookup + ' = ' + str(value) + '". Lookup "' + lookup + '"" not recognised.'
+                'Could not apply filter on search results: "' + field_attname + '__'
+                + lookup + ' = ' + str(value) + '". Lookup "' + lookup + '"" not recognised.'
             )
 
         return result
@@ -132,8 +132,8 @@ class BaseSearchQueryCompiler:
 
             if field is None:
                 raise OrderByFieldError(
-                    'Cannot sort search results with field "' + field_name + '". Please add index.FilterField(\'' +
-                    field_name + '\') to ' + self.queryset.model.__name__ + '.search_fields.',
+                    'Cannot sort search results with field "' + field_name + '". Please add index.FilterField(\''
+                    + field_name + '\') to ' + self.queryset.model.__name__ + '.search_fields.',
                     field_name=field_name
                 )
 
@@ -147,8 +147,8 @@ class BaseSearchQueryCompiler:
             for field_name in self.fields:
                 if field_name not in allowed_fields:
                     raise SearchFieldError(
-                        'Cannot search with field "' + field_name + '". Please add index.SearchField(\'' +
-                        field_name + '\') to ' + self.queryset.model.__name__ + '.search_fields.',
+                        'Cannot search with field "' + field_name + '". Please add index.SearchField(\''
+                        + field_name + '\') to ' + self.queryset.model.__name__ + '.search_fields.',
                         field_name=field_name
                     )
 

+ 2 - 2
wagtail/search/backends/db.py

@@ -125,8 +125,8 @@ class DatabaseSearchResults(BaseSearchResults):
         field = self.query_compiler._get_filterable_field(field_name)
         if field is None:
             raise FilterFieldError(
-                'Cannot facet search results with field "' + field_name + '". Please add index.FilterField(\'' +
-                field_name + '\') to ' + self.query_compiler.queryset.model.__name__ + '.search_fields.',
+                'Cannot facet search results with field "' + field_name + '". Please add index.FilterField(\''
+                + field_name + '\') to ' + self.query_compiler.queryset.model.__name__ + '.search_fields.',
                 field_name=field_name
             )
 

+ 2 - 2
wagtail/search/backends/elasticsearch2.py

@@ -625,8 +625,8 @@ class Elasticsearch2SearchResults(BaseSearchResults):
         field = self.query_compiler._get_filterable_field(field_name)
         if field is None:
             raise FilterFieldError(
-                'Cannot facet search results with field "' + field_name + '". Please add index.FilterField(\'' +
-                field_name + '\') to ' + self.query_compiler.queryset.model.__name__ + '.search_fields.',
+                'Cannot facet search results with field "' + field_name + '". Please add index.FilterField(\''
+                + field_name + '\') to ' + self.query_compiler.queryset.model.__name__ + '.search_fields.',
                 field_name=field_name
             )
 

+ 6 - 5
wagtail/search/tests/test_backends.py

@@ -449,7 +449,6 @@ class BackendTests(WagtailTestUtils):
         with self.assertRaises(FilterFieldError):
             self.backend.search(MATCH_ALL, models.ProgrammingGuide).facet('foo')
 
-
     # MISC TESTS
 
     def test_same_rank_pages(self):
@@ -632,10 +631,12 @@ class BackendTests(WagtailTestUtils):
 
     def test_operators_combination(self):
         results = self.backend.search(
-            ((PlainText('javascript') & ~PlainText('definitive')) |
-             PlainText('python') | PlainText('rust')) |
-            PlainText('two'),
-            models.Book.objects.all())
+            (
+                (PlainText('javascript') & ~PlainText('definitive'))
+                | PlainText('python') | PlainText('rust')
+            ) | PlainText('two'),
+            models.Book.objects.all()
+        )
         self.assertSetEqual({r.title for r in results},
                             {'JavaScript: The good parts',
                              'Learning Python',

+ 2 - 2
wagtail/snippets/views/snippets.py

@@ -263,8 +263,8 @@ def delete(request, app_label, model_name, pk=None):
         'count': count,
         'instances': instances,
         'submit_url': (
-            reverse('wagtailsnippets:delete-multiple', args=(app_label, model_name)) +
-            '?' + urlencode([('id', instance.pk) for instance in instances])
+            reverse('wagtailsnippets:delete-multiple', args=(app_label, model_name))
+            + '?' + urlencode([('id', instance.pk) for instance in instances])
         ),
     })
 

+ 0 - 1
wagtail/tests/dummy_external_storage.py

@@ -26,7 +26,6 @@ class DummyExternalStorage(Storage):
         # File object
         return DummyExternalStorageFile(open(self.wrapped.path(name), mode))
 
-
     # Wrap all other functions
 
     def _save(self, name, content):

+ 9 - 9
wagtail/users/wagtail_hooks.py

@@ -37,9 +37,9 @@ delete_user_perm = "{0}.delete_{1}".format(AUTH_USER_APP_LABEL, AUTH_USER_MODEL_
 class UsersMenuItem(MenuItem):
     def is_shown(self, request):
         return (
-            request.user.has_perm(add_user_perm) or
-            request.user.has_perm(change_user_perm) or
-            request.user.has_perm(delete_user_perm)
+            request.user.has_perm(add_user_perm)
+            or request.user.has_perm(change_user_perm)
+            or request.user.has_perm(delete_user_perm)
         )
 
 
@@ -56,9 +56,9 @@ def register_users_menu_item():
 class GroupsMenuItem(MenuItem):
     def is_shown(self, request):
         return (
-            request.user.has_perm('auth.add_group') or
-            request.user.has_perm('auth.change_group') or
-            request.user.has_perm('auth.delete_group')
+            request.user.has_perm('auth.add_group')
+            or request.user.has_perm('auth.change_group')
+            or request.user.has_perm('auth.delete_group')
         )
 
 
@@ -87,9 +87,9 @@ def register_permissions():
 class UsersSearchArea(SearchArea):
     def is_shown(self, request):
         return (
-            request.user.has_perm(add_user_perm) or
-            request.user.has_perm(change_user_perm) or
-            request.user.has_perm(delete_user_perm)
+            request.user.has_perm(add_user_perm)
+            or request.user.has_perm(change_user_perm)
+            or request.user.has_perm(delete_user_perm)
         )