Browse Source

Readd default disables to pylint

rafalp 6 years ago
parent
commit
a44438df2b

+ 3 - 0
.pylintrc

@@ -10,7 +10,9 @@ max-line-length=88
 disable=
 disable=
     abstract-method,
     abstract-method,
     arguments-differ,
     arguments-differ,
+    attribute-defined-outside-init,
     bad-continuation,
     bad-continuation,
+    duplicate-code,
     expression-not-assigned,
     expression-not-assigned,
     fixme,
     fixme,
     inconsistent-return-statements,
     inconsistent-return-statements,
@@ -18,6 +20,7 @@ disable=
     missing-docstring,
     missing-docstring,
     no-member,
     no-member,
     no-self-use,
     no-self-use,
+    protected-access,
     redefined-outer-name,
     redefined-outer-name,
     too-few-public-methods,
     too-few-public-methods,
     too-many-ancestors,
     too-many-ancestors,

+ 1 - 1
.travis.yml

@@ -24,4 +24,4 @@ jobs:
         - pip install black pylint pylint-django
         - pip install black pylint pylint-django
       script:
       script:
         - black --check devproject misago
         - black --check devproject misago
-        - pylint misago/acl misago/admin misago/cache
+        - pylint misago/acl misago/admin misago/cache misago/conf misago/core

+ 0 - 1
misago/acl/tests/test_providers.py

@@ -1,4 +1,3 @@
-# pylint: disable=protected-access
 import pytest
 import pytest
 
 
 from ...conf import settings
 from ...conf import settings

+ 0 - 1
misago/cache/test.py

@@ -4,7 +4,6 @@ from .versions import get_cache_versions_from_db
 class assert_invalidates_cache:
 class assert_invalidates_cache:
     def __init__(self, cache):
     def __init__(self, cache):
         self.cache = cache
         self.cache = cache
-        self.versions = None
 
 
     def __enter__(self):
     def __enter__(self):
         self.versions = get_cache_versions_from_db()
         self.versions = get_cache_versions_from_db()

+ 2 - 4
misago/core/apipatch.py

@@ -50,8 +50,7 @@ class ApiPatch:
         patch["detail"] = detail
         patch["detail"] = detail
         if is_errored:
         if is_errored:
             return Response(patch, status=400)
             return Response(patch, status=400)
-        else:
-            return Response(patch)
+        return Response(patch)
 
 
     def dispatch_bulk(self, request, targets):
     def dispatch_bulk(self, request, targets):
         is_errored = False
         is_errored = False
@@ -79,8 +78,7 @@ class ApiPatch:
 
 
         if is_errored:
         if is_errored:
             return Response(result, status=400)
             return Response(result, status=400)
-        else:
-            return Response(result)
+        return Response(result)
 
 
     def validate_action(self, action):
     def validate_action(self, action):
         if not action.get("op"):
         if not action.get("op"):

+ 1 - 2
misago/core/context_processors.py

@@ -44,5 +44,4 @@ def momentjs_locale(request):
 def frontend_context(request):
 def frontend_context(request):
     if request.include_frontend_context:
     if request.include_frontend_context:
         return {"frontend_context": request.frontend_context}
         return {"frontend_context": request.frontend_context}
-    else:
-        return {}
+    return {}

+ 2 - 4
misago/core/decorators.py

@@ -7,8 +7,7 @@ def ajax_only(f):
     def decorator(request, *args, **kwargs):
     def decorator(request, *args, **kwargs):
         if not request.is_ajax():
         if not request.is_ajax():
             return not_allowed(request)
             return not_allowed(request)
-        else:
-            return f(request, *args, **kwargs)
+        return f(request, *args, **kwargs)
 
 
     return decorator
     return decorator
 
 
@@ -17,8 +16,7 @@ def require_POST(f):
     def decorator(request, *args, **kwargs):
     def decorator(request, *args, **kwargs):
         if not request.method == "POST":
         if not request.method == "POST":
             return not_allowed(request)
             return not_allowed(request)
-        else:
-            return f(request, *args, **kwargs)
+        return f(request, *args, **kwargs)
 
 
     return decorator
     return decorator
 
 

+ 11 - 13
misago/core/errorpages.py

@@ -40,15 +40,13 @@ def banned(request, exception):
 def permission_denied(request, exception):
 def permission_denied(request, exception):
     if request.is_ajax():
     if request.is_ajax():
         return _ajax_error(403, exception, _("Permission denied."))
         return _ajax_error(403, exception, _("Permission denied."))
-    else:
-        return _error_page(request, 403, exception)
+    return _error_page(request, 403, exception)
 
 
 
 
 def page_not_found(request, exception):
 def page_not_found(request, exception):
     if request.is_ajax():
     if request.is_ajax():
         return _ajax_error(404, exception, "Not found.")
         return _ajax_error(404, exception, "Not found.")
-    else:
-        return _error_page(request, 404, exception)
+    return _error_page(request, 404, exception)
 
 
 
 
 def social_auth_failed(request, exception):
 def social_auth_failed(request, exception):
@@ -61,6 +59,7 @@ def social_auth_failed(request, exception):
         backend_name = exception.backend_name
         backend_name = exception.backend_name
     except AttributeError:
     except AttributeError:
         pass
         pass
+
     try:
     try:
         exception_backend = exception.backend
         exception_backend = exception.backend
         backend_name = get_social_auth_backend_name(exception_backend.name)
         backend_name = get_social_auth_backend_name(exception_backend.name)
@@ -69,7 +68,8 @@ def social_auth_failed(request, exception):
 
 
     if isinstance(exception, social_exceptions.NotAllowedToDisconnect):
     if isinstance(exception, social_exceptions.NotAllowedToDisconnect):
         message = _(
         message = _(
-            "A problem was encountered when disconnecting your account from the remote site."
+            "A problem was encountered when disconnecting your account "
+            "from the remote site."
         )
         )
         help_text = _(
         help_text = _(
             "You are not allowed to disconnect your account from the other site, "
             "You are not allowed to disconnect your account from the other site, "
@@ -108,10 +108,10 @@ def social_auth_failed(request, exception):
 def csrf_failure(request, reason=""):
 def csrf_failure(request, reason=""):
     if request.is_ajax():
     if request.is_ajax():
         return _ajax_error(403, _("Request authentication is invalid."))
         return _ajax_error(403, _("Request authentication is invalid."))
-    else:
-        response = render(request, "misago/errorpages/csrf_failure.html")
-        response.status_code = 403
-        return response
+
+    response = render(request, "misago/errorpages/csrf_failure.html")
+    response.status_code = 403
+    return response
 
 
 
 
 def not_allowed(request):
 def not_allowed(request):
@@ -123,8 +123,7 @@ def shared_403_exception_handler(f):
     def page_decorator(request, *args, **kwargs):
     def page_decorator(request, *args, **kwargs):
         if is_request_to_misago(request):
         if is_request_to_misago(request):
             return permission_denied(request, *args, **kwargs)
             return permission_denied(request, *args, **kwargs)
-        else:
-            return f(request, *args, **kwargs)
+        return f(request, *args, **kwargs)
 
 
     return page_decorator
     return page_decorator
 
 
@@ -133,7 +132,6 @@ def shared_404_exception_handler(f):
     def page_decorator(request, *args, **kwargs):
     def page_decorator(request, *args, **kwargs):
         if is_request_to_misago(request):
         if is_request_to_misago(request):
             return page_not_found(request, *args, **kwargs)
             return page_not_found(request, *args, **kwargs)
-        else:
-            return f(request, *args, **kwargs)
+        return f(request, *args, **kwargs)
 
 
     return page_decorator
     return page_decorator

+ 2 - 4
misago/core/exceptionhandler.py

@@ -83,8 +83,7 @@ def get_exception_handler(exception):
     for exception_type, handler in EXCEPTION_HANDLERS:
     for exception_type, handler in EXCEPTION_HANDLERS:
         if isinstance(exception, exception_type):
         if isinstance(exception, exception_type):
             return handler
             return handler
-    else:
-        raise ValueError("%s is not Misago exception" % exception.__class__.__name__)
+    raise ValueError("%s is not a Misago exception" % exception.__class__.__name__)
 
 
 
 
 def handle_misago_exception(request, exception):
 def handle_misago_exception(request, exception):
@@ -103,5 +102,4 @@ def handle_api_exception(exception, context):
             except IndexError:
             except IndexError:
                 pass
                 pass
         return response
         return response
-    else:
-        return None
+    return None

+ 1 - 4
misago/core/exceptions.py

@@ -1,3 +1,4 @@
+# pylint: disable=super-init-not-called
 from django.core.exceptions import PermissionDenied
 from django.core.exceptions import PermissionDenied
 from social_core.exceptions import AuthException
 from social_core.exceptions import AuthException
 
 
@@ -35,10 +36,6 @@ class SocialAuthBanned(AuthException):
 class ExplicitFirstPage(Exception):
 class ExplicitFirstPage(Exception):
     """The url that was used to reach view contained explicit first page"""
     """The url that was used to reach view contained explicit first page"""
 
 
-    pass
-
 
 
 class OutdatedSlug(Exception):
 class OutdatedSlug(Exception):
     """The url that was used to reach view contained outdated slug"""
     """The url that was used to reach view contained outdated slug"""
-
-    pass

+ 0 - 2
misago/core/middleware.py

@@ -11,8 +11,6 @@ class ExceptionHandlerMiddleware(MiddlewareMixin):
 
 
         if request_is_to_misago and misago_can_handle_exception:
         if request_is_to_misago and misago_can_handle_exception:
             return exceptionhandler.handle_misago_exception(request, exception)
             return exceptionhandler.handle_misago_exception(request, exception)
-        else:
-            return None
 
 
 
 
 class FrontendContextMiddleware(MiddlewareMixin):
 class FrontendContextMiddleware(MiddlewareMixin):

+ 12 - 11
misago/core/page.py

@@ -22,7 +22,10 @@ class Page:
         while self._unsorted_list:
         while self._unsorted_list:
             iterations += 1
             iterations += 1
             if iterations > 512:
             if iterations > 512:
-                message = "%s page hierarchy is invalid or too complex  to resolve. Sections left: %s"
+                message = (
+                    "%s page hierarchy is invalid or too complex to resolve. "
+                    "Sections left: %s"
+                )
                 raise ValueError(message % self._unsorted_list)
                 raise ValueError(message % self._unsorted_list)
 
 
             for index, section in enumerate(self._unsorted_list):
             for index, section in enumerate(self._unsorted_list):
@@ -50,9 +53,9 @@ class Page:
                     new_sorted_list.append(inserted_section)
                     new_sorted_list.append(inserted_section)
                     self._sorted_list = new_sorted_list
                     self._sorted_list = new_sorted_list
                     return True
                     return True
-            else:
-                return False
-        elif before:
+            return False
+
+        if before:
             new_sorted_list = []
             new_sorted_list = []
             for section in self._sorted_list:
             for section in self._sorted_list:
                 if section["link"] == before:
                 if section["link"] == before:
@@ -60,13 +63,11 @@ class Page:
                     new_sorted_list.append(section)
                     new_sorted_list.append(section)
                     self._sorted_list = new_sorted_list
                     self._sorted_list = new_sorted_list
                     return True
                     return True
-                else:
-                    new_sorted_list.append(section)
-            else:
-                return False
-        else:
-            self._sorted_list.append(inserted_section)
-            return True
+                new_sorted_list.append(section)
+            return False
+
+        self._sorted_list.append(inserted_section)
+        return True
 
 
     def add_section(
     def add_section(
         self,
         self,

+ 13 - 12
misago/core/pgutils.py

@@ -1,4 +1,3 @@
-from django.core.paginator import Paginator
 from django.db.models import Index
 from django.db.models import Index
 
 
 
 
@@ -6,11 +5,13 @@ class PgPartialIndex(Index):
     suffix = "part"
     suffix = "part"
     max_name_length = 31
     max_name_length = 31
 
 
-    def __init__(self, fields=[], name=None, where=None):
+    def __init__(self, fields=None, name=None, where=None):
         if not where:
         if not where:
             raise ValueError("partial index requires WHERE clause")
             raise ValueError("partial index requires WHERE clause")
         self.where = where
         self.where = where
 
 
+        fields = fields or []
+
         super().__init__(fields, name)
         super().__init__(fields, name)
 
 
     def set_name_with_model(self, model):
     def set_name_with_model(self, model):
@@ -37,18 +38,18 @@ class PgPartialIndex(Index):
         self.check_name()
         self.check_name()
 
 
     def __repr__(self):
     def __repr__(self):
-        if self.where is not None:
-            where_items = []
-            for key in sorted(self.where.keys()):
-                where_items.append("=".join([key, repr(self.where[key])]))
-            return "<%(name)s: fields=%(fields)s, where=%(where)s>" % {
-                "name": self.__class__.__name__,
-                "fields": "'%s'" % (", ".join(self.fields)),
-                "where": "'%s'" % (", ".join(where_items)),
-            }
-        else:
+        if self.where is None:
             return super().__repr__()
             return super().__repr__()
 
 
+        where_items = []
+        for key in sorted(self.where.keys()):
+            where_items.append("=".join([key, repr(self.where[key])]))
+        return "<%(name)s: fields=%(fields)s, where=%(where)s>" % {
+            "name": self.__class__.__name__,
+            "fields": "'%s'" % (", ".join(self.fields)),
+            "where": "'%s'" % (", ".join(where_items)),
+        }
+
     def deconstruct(self):
     def deconstruct(self):
         path, args, kwargs = super().deconstruct()
         path, args, kwargs = super().deconstruct()
         kwargs["where"] = self.where
         kwargs["where"] = self.where

+ 2 - 3
misago/core/shortcuts.py

@@ -16,7 +16,7 @@ def paginate(
 
 
     if page in (1, "1") and not allow_explicit_first_page:
     if page in (1, "1") and not allow_explicit_first_page:
         raise ExplicitFirstPage()
         raise ExplicitFirstPage()
-    elif not page:
+    if not page:
         page = 1
         page = 1
 
 
     paginator = paginator or Paginator
     paginator = paginator or Paginator
@@ -85,5 +85,4 @@ def validate_slug(model, slug):
 def get_int_or_404(value):
 def get_int_or_404(value):
     if str(value).isdigit():
     if str(value).isdigit():
         return int(value)
         return int(value)
-    else:
-        raise Http404()
+    raise Http404()

+ 1 - 1
misago/core/testproject/urlswitherrorhandlers.py

@@ -1,4 +1,4 @@
-from .urls import *
+from .urls import *  # pylint: disable=wildcard-import, unused-wildcard-import
 
 
 handler403 = "misago.core.testproject.views.mock_custom_403_error_page"
 handler403 = "misago.core.testproject.views.mock_custom_403_error_page"
 handler404 = "misago.core.testproject.views.mock_custom_404_error_page"
 handler404 = "misago.core.testproject.views.mock_custom_404_error_page"

+ 2 - 2
misago/core/tests/test_errorpages.py

@@ -66,7 +66,7 @@ class ErrorPageViewsTests(TestCase):
         self.assertContains(response, "page-error-social", status_code=403)
         self.assertContains(response, "page-error-social", status_code=403)
 
 
     def test_social_failed_message(self):
     def test_social_failed_message(self):
-        """misago-specific social auth failed exception error page returns 403 with message"""
+        """misago-specific social auth failed error page returns 403 with message"""
         response = self.client.get(reverse("raise-social-auth-failed-message"))
         response = self.client.get(reverse("raise-social-auth-failed-message"))
         self.assertContains(response, "page-error-social", status_code=403)
         self.assertContains(response, "page-error-social", status_code=403)
         self.assertContains(
         self.assertContains(
@@ -74,7 +74,7 @@ class ErrorPageViewsTests(TestCase):
         )
         )
 
 
     def test_social_auth_banned(self):
     def test_social_auth_banned(self):
-        """misago-specific social auth banned exception error page returns 403 with ban message"""
+        """misago-specific social auth banned error page returns 403 with ban message"""
         response = self.client.get(reverse("raise-social-auth-banned"))
         response = self.client.get(reverse("raise-social-auth-banned"))
         self.assertContains(response, "page-error-social", status_code=403)
         self.assertContains(response, "page-error-social", status_code=403)
         self.assertContains(response, "Banned in auth!", status_code=403)
         self.assertContains(response, "Banned in auth!", status_code=403)

+ 1 - 1
misago/core/tests/test_jsi18n.py

@@ -30,7 +30,7 @@ class JsI18nUrlTests(TestCase):
                     response = self.client.get(reverse("django-i18n"))
                     response = self.client.get(reverse("django-i18n"))
                     if response.status_code != 200:
                     if response.status_code != 200:
                         failed_languages.append(language)
                         failed_languages.append(language)
-            except:
+            except:  # pylint: disable=bare-except
                 failed_languages.append(language)
                 failed_languages.append(language)
 
 
         if failed_languages:
         if failed_languages:

+ 7 - 1
misago/core/tests/test_utils.py

@@ -95,7 +95,13 @@ PLAINTEXT_FORMAT_CASES = [
     ("Lorem ipsum.\n\nDolor met.", "<p>Lorem ipsum.</p>\n\n<p>Dolor met.</p>"),
     ("Lorem ipsum.\n\nDolor met.", "<p>Lorem ipsum.</p>\n\n<p>Dolor met.</p>"),
     (
     (
         "http://misago-project.org/login/",
         "http://misago-project.org/login/",
-        '<p><a href="http://misago-project.org/login/">http://misago-project.org/login/</a></p>',
+        (
+            '<p>'
+            '<a href="http://misago-project.org/login/">'
+            'http://misago-project.org/login/'
+            '</a>'
+            '</p>'
+        ),
     ),
     ),
 ]
 ]
 
 

+ 4 - 5
misago/core/utils.py

@@ -28,13 +28,13 @@ def parse_iso8601_string(value):
     """turns ISO 8601 string into datetime object"""
     """turns ISO 8601 string into datetime object"""
     value = force_text(value, strings_only=True).rstrip("Z")
     value = force_text(value, strings_only=True).rstrip("Z")
 
 
-    for format in ISO8601_FORMATS:
+    for format_str in ISO8601_FORMATS:
         try:
         try:
-            parsed_value = datetime.strptime(value, format)
+            parsed_value = datetime.strptime(value, format_str)
             break
             break
         except ValueError:
         except ValueError:
             try:
             try:
-                parsed_value = datetime.strptime(value[:-6], format)
+                parsed_value = datetime.strptime(value[:-6], format_str)
                 break
                 break
             except ValueError:
             except ValueError:
                 pass
                 pass
@@ -67,8 +67,7 @@ def clean_return_path(request):
     """return path utility that returns return path from referer or POST"""
     """return path utility that returns return path from referer or POST"""
     if request.method == "POST" and "return_path" in request.POST:
     if request.method == "POST" and "return_path" in request.POST:
         return _get_return_path_from_post(request)
         return _get_return_path_from_post(request)
-    else:
-        return _get_return_path_from_referer(request)
+    return _get_return_path_from_referer(request)
 
 
 
 
 def _get_return_path_from_post(request):
 def _get_return_path_from_post(request):