Skip to content

Commit

Permalink
Fix linting failures for flake8 3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
gasman committed Oct 25, 2018
1 parent c2a351f commit 33e290b
Show file tree
Hide file tree
Showing 38 changed files with 99 additions and 125 deletions.
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@

# 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',
Expand Down
3 changes: 2 additions & 1 deletion tox.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
2 changes: 0 additions & 2 deletions wagtail/admin/tests/api/test_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ def get_response(self, **params):
def get_document_id_list(self, content):
return [document['id'] for document in content['items']]


# BASIC TESTS

def test_basic(self):
Expand Down Expand Up @@ -57,7 +56,6 @@ def test_basic(self):
# Check download_url
self.assertTrue(document['meta']['download_url'].startswith('http://localhost/documents/%d/' % document['id']))


# FIELDS

def test_fields_default(self):
Expand Down
2 changes: 0 additions & 2 deletions wagtail/admin/tests/api/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def get_response(self, **params):
def get_image_id_list(self, content):
return [image['id'] for image in content['items']]


# BASIC TESTS

def test_basic(self):
Expand Down Expand Up @@ -55,7 +54,6 @@ def test_basic(self):
# Check detail url
self.assertEqual(image['meta']['detail_url'], 'http://localhost/admin/api/v2beta/images/%d/' % image['id'])


# FIELDS

def test_fields_default(self):
Expand Down
2 changes: 0 additions & 2 deletions wagtail/admin/tests/api/test_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def get_response(self, **params):
def get_page_id_list(self, content):
return [page['id'] for page in content['items']]


# BASIC TESTS

def test_basic(self):
Expand Down Expand Up @@ -298,7 +297,6 @@ def test_descendant_of_root_doesnt_give_error(self):

self.assertEqual(response.status_code, 200)


# FOR EXPLORER FILTER

def make_simple_page(self, parent, title):
Expand Down
8 changes: 4 additions & 4 deletions wagtail/admin/views/generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -185,8 +185,8 @@ def form_invalid(self, form):
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

Expand Down
14 changes: 7 additions & 7 deletions wagtail/admin/views/pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions wagtail/admin/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,11 +264,11 @@ def __lt__(self, other):
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):
Expand Down
7 changes: 0 additions & 7 deletions wagtail/api/v2/tests/test_documents.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def get_response(self, **params):
def get_document_id_list(self, content):
return [document['id'] for document in content['items']]


# BASIC TESTS

def test_basic(self):
Expand Down Expand Up @@ -58,7 +57,6 @@ def test_basic(self):
# Check download_url
self.assertTrue(document['meta']['download_url'].startswith('http://localhost/documents/%d/' % document['id']))


# FIELDS

def test_fields_default(self):
Expand Down Expand Up @@ -157,7 +155,6 @@ def test_fields_remove_unknown_field_gives_error(self):
self.assertEqual(response.status_code, 400)
self.assertEqual(content, {'message': "unknown fields: 123, abc"})


# FILTERING

def test_filtering_exact_filter(self):
Expand Down Expand Up @@ -190,7 +187,6 @@ def test_filtering_unknown_field_gives_error(self):
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):
Expand Down Expand Up @@ -239,7 +235,6 @@ def test_ordering_by_unknown_field_gives_error(self):
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):
Expand Down Expand Up @@ -294,7 +289,6 @@ def test_limit_default_changes_with_max(self):

self.assertEqual(len(content['items']), 2)


# OFFSET

def test_offset_5_usually_appears_5th_in_list(self):
Expand Down Expand Up @@ -323,7 +317,6 @@ def test_offset_not_integer_gives_error(self):
self.assertEqual(response.status_code, 400)
self.assertEqual(content, {'message': "offset must be a positive integer"})


# SEARCH

def test_search_for_james_joyce(self):
Expand Down
7 changes: 0 additions & 7 deletions wagtail/api/v2/tests/test_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ def get_response(self, **params):
def get_image_id_list(self, content):
return [image['id'] for image in content['items']]


# BASIC TESTS

def test_basic(self):
Expand Down Expand Up @@ -55,7 +54,6 @@ def test_basic(self):
# Check detail url
self.assertEqual(image['meta']['detail_url'], 'http://localhost/api/v2beta/images/%d/' % image['id'])


# FIELDS

def test_fields_default(self):
Expand Down Expand Up @@ -157,7 +155,6 @@ def test_fields_remove_unknown_field_gives_error(self):
self.assertEqual(response.status_code, 400)
self.assertEqual(content, {'message': "unknown fields: 123, abc"})


# FILTERING

def test_filtering_exact_filter(self):
Expand Down Expand Up @@ -190,7 +187,6 @@ def test_filtering_unknown_field_gives_error(self):
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):
Expand Down Expand Up @@ -239,7 +235,6 @@ def test_ordering_by_unknown_field_gives_error(self):
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):
Expand Down Expand Up @@ -294,7 +289,6 @@ def test_limit_default_changes_with_max(self):

self.assertEqual(len(content['items']), 2)


# OFFSET

def test_offset_10_usually_appears_7th_in_list(self):
Expand Down Expand Up @@ -323,7 +317,6 @@ def test_offset_not_integer_gives_error(self):
self.assertEqual(response.status_code, 400)
self.assertEqual(content, {'message': "offset must be a positive integer"})


# SEARCH

def test_search_for_james_joyce(self):
Expand Down
8 changes: 0 additions & 8 deletions wagtail/api/v2/tests/test_pages.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ def get_response(self, **params):
def get_page_id_list(self, content):
return [page['id'] for page in content['items']]


# BASIC TESTS

def test_basic(self):
Expand Down Expand Up @@ -361,7 +360,6 @@ def test_nested_fields_on_non_relational_field_gives_error(self):
self.assertEqual(response.status_code, 400)
self.assertEqual(content, {'message': "'title' does not support nested fields"})


# FILTERING

def test_filtering_exact_filter(self):
Expand Down Expand Up @@ -434,7 +432,6 @@ def test_filtering_boolean_validation(self):
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):
Expand Down Expand Up @@ -481,7 +478,6 @@ def test_child_of_page_thats_not_in_same_site_gives_error(self):
self.assertEqual(response.status_code, 400)
self.assertEqual(content, {'message': "parent page doesn't exist"})


# DESCENDANT OF FILTER

def test_descendant_of_filter(self):
Expand Down Expand Up @@ -536,7 +532,6 @@ def test_descendant_of_when_filtering_by_child_of_gives_error(self):
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):
Expand Down Expand Up @@ -613,7 +608,6 @@ def test_ordering_by_unknown_field_gives_error(self):
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):
Expand Down Expand Up @@ -668,7 +662,6 @@ def test_limit_default_changes_with_max(self):

self.assertEqual(len(content['items']), 2)


# OFFSET

def test_offset_5_usually_appears_5th_in_list(self):
Expand Down Expand Up @@ -697,7 +690,6 @@ def test_offset_not_integer_gives_error(self):
self.assertEqual(response.status_code, 400)
self.assertEqual(content, {'message': "offset must be a positive integer"})


# SEARCH

def test_search_for_blog(self):
Expand Down
2 changes: 0 additions & 2 deletions wagtail/api/v2/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ def test_valid_field_with_underscore_at_end(self):
('test_', False, None),
])


# BAD STUFF

def test_invalid_char(self):
Expand Down Expand Up @@ -258,7 +257,6 @@ def test_valid_0(self):

self.assertEqual(parsed, False)


# BAD STUFF

def test_invalid(self):
Expand Down
4 changes: 2 additions & 2 deletions wagtail/contrib/modeladmin/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,8 @@ def get_inspect_view_fields(self):
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
Expand Down
8 changes: 4 additions & 4 deletions wagtail/contrib/postgres_search/backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,8 @@ def search(self, config, start, stop, score_field=None):
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':
Expand Down Expand Up @@ -379,8 +379,8 @@ def facet(self, field_name):
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
)

Expand Down
6 changes: 3 additions & 3 deletions wagtail/contrib/redirects/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
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.
Expand Down
Loading

0 comments on commit 33e290b

Please sign in to comment.