From 3f9cda71b507948c2fd912f9df961a172d019ac1 Mon Sep 17 00:00:00 2001
From: Ned Batchelder <ned@edx.org>
Date: Wed, 2 Sep 2020 13:23:45 -0400
Subject: [PATCH] Fix pylint violations (mostly removing pylint pragmas)

---
 lti_consumer/lti_1p1/consumer.py           |  4 ++--
 lti_consumer/lti_1p1/oauth.py              |  6 +++---
 lti_consumer/lti_1p3/exceptions.py         |  1 -
 lti_consumer/lti_xblock.py                 | 21 ++++++++++-----------
 lti_consumer/outcomes.py                   |  8 ++++----
 lti_consumer/plugin/views.py               |  2 +-
 lti_consumer/tests/unit/test_lti_xblock.py |  6 +++---
 lti_consumer/tests/unit/test_models.py     |  4 ++--
 lti_consumer/utils.py                      |  2 +-
 setup.cfg                                  |  4 +++-
 10 files changed, 29 insertions(+), 29 deletions(-)

diff --git a/lti_consumer/lti_1p1/consumer.py b/lti_consumer/lti_1p1/consumer.py
index 4903439..c034e0b 100644
--- a/lti_consumer/lti_1p1/consumer.py
+++ b/lti_consumer/lti_1p1/consumer.py
@@ -117,7 +117,7 @@ def parse_result_json(json_str):
     return score, json_obj.get('comment', "")
 
 
-class LtiConsumer1p1(object):  # pylint: disable=bad-option-value, useless-object-inheritance
+class LtiConsumer1p1:
     """
     Limited implementation of the LTI 1.1.
 
@@ -319,7 +319,7 @@ class LtiConsumer1p1(object):  # pylint: disable=bad-option-value, useless-objec
         lti_parameters.update(oauth_signature)
         return lti_parameters
 
-    def get_result(self, result_score=None, score_comment=None):  # pylint: disable=unused-argument
+    def get_result(self, result_score=None, score_comment=None):
         """
         Returns response body for GET requests to LTI 2.0 result endpoint
 
diff --git a/lti_consumer/lti_1p1/oauth.py b/lti_consumer/lti_1p1/oauth.py
index 61f8daa..5318858 100644
--- a/lti_consumer/lti_1p1/oauth.py
+++ b/lti_consumer/lti_1p1/oauth.py
@@ -14,7 +14,7 @@ from .exceptions import Lti1p1Error
 log = logging.getLogger(__name__)
 
 
-class SignedRequest(object):  # pylint: disable=bad-option-value, useless-object-inheritance
+class SignedRequest:
     """
     Encapsulates request attributes needed when working
     with the `oauthlib.oauth1` API
@@ -88,7 +88,7 @@ def verify_oauth_body_signature(request, lti_provider_secret, service_url):
 
     sha1 = hashlib.sha1()
     sha1.update(request.body)
-    oauth_body_hash = base64.b64encode(sha1.digest())  # pylint: disable=E1121
+    oauth_body_hash = base64.b64encode(sha1.digest())
     oauth_params = oauth1.rfc5849.signature.collect_parameters(headers=headers, exclude_oauth_signature=False)
     oauth_headers = dict(oauth_params)
     oauth_signature = oauth_headers.pop('oauth_signature')
@@ -144,7 +144,7 @@ def log_authorization_header(request, client_key, client_secret):
     """
     sha1 = hashlib.sha1()
     sha1.update(request.body)
-    oauth_body_hash = str(base64.b64encode(sha1.digest()))  # pylint: disable=too-many-function-args
+    oauth_body_hash = str(base64.b64encode(sha1.digest()))
     log.debug("[LTI] oauth_body_hash = %s", oauth_body_hash)
     client = oauth1.Client(client_key, client_secret)
     params = client.get_oauth_params(request)
diff --git a/lti_consumer/lti_1p3/exceptions.py b/lti_consumer/lti_1p3/exceptions.py
index 47169d3..d27d4a3 100644
--- a/lti_consumer/lti_1p3/exceptions.py
+++ b/lti_consumer/lti_1p3/exceptions.py
@@ -3,7 +3,6 @@ Custom exceptions for LTI 1.3 consumer
 
 # TODO: Improve exception documentation and output.
 """
-# pylint: disable=missing-docstring
 
 
 class Lti1p3Exception(Exception):
diff --git a/lti_consumer/lti_xblock.py b/lti_consumer/lti_xblock.py
index b2a8dfb..133da3e 100644
--- a/lti_consumer/lti_xblock.py
+++ b/lti_consumer/lti_xblock.py
@@ -139,7 +139,7 @@ def parse_handler_suffix(suffix):
 LaunchTargetOption = namedtuple('LaunchTargetOption', ['display_name', 'value'])
 
 
-class LaunchTarget(object):  # pylint: disable=bad-option-value, useless-object-inheritance
+class LaunchTarget:
     """
     Constants for launch_target field options
     """
@@ -633,7 +633,7 @@ class LtiConsumerXBlock(StudioEditableXBlockMixin, XBlock):
         context_id is an opaque identifier that uniquely identifies the context (e.g., a course)
         that contains the link being launched.
         """
-        return str(self.course_id)  # pylint: disable=no-member
+        return str(self.course_id)
 
     @property
     def role(self):
@@ -647,7 +647,7 @@ class LtiConsumerXBlock(StudioEditableXBlockMixin, XBlock):
         """
         Return course by course id.
         """
-        return self.runtime.modulestore.get_course(self.runtime.course_id)  # pylint: disable=no-member
+        return self.runtime.modulestore.get_course(self.runtime.course_id)
 
     @property
     def lti_provider_key_secret(self):
@@ -959,7 +959,7 @@ class LtiConsumerXBlock(StudioEditableXBlockMixin, XBlock):
         return fragment
 
     @XBlock.handler
-    def lti_launch_handler(self, request, suffix=''):  # pylint: disable=unused-argument
+    def lti_launch_handler(self, request, suffix=''):
         """
         XBlock handler for launching LTI 1.1 tools.
 
@@ -1014,7 +1014,7 @@ class LtiConsumerXBlock(StudioEditableXBlockMixin, XBlock):
         return Response(template, content_type='text/html')
 
     @XBlock.handler
-    def lti_1p3_launch_handler(self, request, suffix=''):  # pylint: disable=unused-argument
+    def lti_1p3_launch_handler(self, request, suffix=''):
         """
         XBlock handler for launching the LTI 1.3 tools.
 
@@ -1039,7 +1039,7 @@ class LtiConsumerXBlock(StudioEditableXBlockMixin, XBlock):
         return Response(template, content_type='text/html')
 
     @XBlock.handler
-    def lti_1p3_launch_callback(self, request, suffix=''):  # pylint: disable=unused-argument
+    def lti_1p3_launch_callback(self, request, suffix=''):
         """
         XBlock handler for launching the LTI 1.3 tool.
 
@@ -1100,7 +1100,7 @@ class LtiConsumerXBlock(StudioEditableXBlockMixin, XBlock):
             return Response(template, status=400, content_type='text/html')
 
     @XBlock.handler
-    def public_keyset_endpoint(self, request, suffix=''):  # pylint: disable=unused-argument
+    def public_keyset_endpoint(self, request, suffix=''):
         """
         XBlock handler for launching the LTI provider.
         """
@@ -1113,7 +1113,7 @@ class LtiConsumerXBlock(StudioEditableXBlockMixin, XBlock):
         return Response(status=404)
 
     @XBlock.handler
-    def lti_1p3_access_token(self, request, suffix=''):  # pylint: disable=unused-argument
+    def lti_1p3_access_token(self, request, suffix=''):
         """
         XBlock handler for creating access tokens for the LTI 1.3 tool.
 
@@ -1146,7 +1146,6 @@ class LtiConsumerXBlock(StudioEditableXBlockMixin, XBlock):
             return Response(json_body=token, content_type="application/json")
 
         # Handle errors and return a proper response
-        # pylint: disable=bare-except
         except MissingRequiredClaim:
             # Missing request attibutes
             return Response(
@@ -1173,7 +1172,7 @@ class LtiConsumerXBlock(StudioEditableXBlockMixin, XBlock):
             )
 
     @XBlock.handler
-    def outcome_service_handler(self, request, suffix=''):  # pylint: disable=unused-argument
+    def outcome_service_handler(self, request, suffix=''):
         """
         XBlock handler for LTI Outcome Service requests.
 
@@ -1409,7 +1408,7 @@ class LtiConsumerXBlock(StudioEditableXBlockMixin, XBlock):
             'launch_url': self.launch_url.strip(),
             'lti_1p3_launch_url': self.lti_1p3_launch_url.strip(),
             'element_id': self.location.html_id(),  # pylint: disable=no-member
-            'element_class': self.category,  # pylint: disable=no-member
+            'element_class': self.category,
             'launch_target': self.launch_target,
             'display_name': self.display_name,
             'form_url': lti_block_launch_handler,
diff --git a/lti_consumer/outcomes.py b/lti_consumer/outcomes.py
index a0249d0..f3d026b 100644
--- a/lti_consumer/outcomes.py
+++ b/lti_consumer/outcomes.py
@@ -43,8 +43,8 @@ def parse_grade_xml_body(body):
         data = body.strip().encode('utf-8')
 
     try:
-        parser = etree.XMLParser(ns_clean=True, recover=True, encoding='utf-8')  # pylint: disable=no-member
-        root = etree.fromstring(data, parser=parser)  # pylint: disable=no-member
+        parser = etree.XMLParser(ns_clean=True, recover=True, encoding='utf-8')
+        root = etree.fromstring(data, parser=parser)
     except etree.XMLSyntaxError as ex:
         raise LtiError(str(ex) or 'Body is not valid XML')
 
@@ -81,7 +81,7 @@ def parse_grade_xml_body(body):
     return imsx_message_identifier, sourced_id, score, action
 
 
-class OutcomeService(object):  # pylint: disable=bad-option-value, useless-object-inheritance
+class OutcomeService:
     """
     Service for handling LTI Outcome Management Service requests.
 
@@ -165,7 +165,7 @@ class OutcomeService(object):  # pylint: disable=bad-option-value, useless-objec
 
         try:
             imsx_message_identifier, sourced_id, score, action = parse_grade_xml_body(request_body)
-        except LtiError as ex:  # pylint: disable=no-member
+        except LtiError as ex:
             body = escape(request_body) if request_body else ''
             error_message = "Request body XML parsing error: {} {}".format(str(ex), body)
             log.debug("[LTI]: %s", error_message)
diff --git a/lti_consumer/plugin/views.py b/lti_consumer/plugin/views.py
index 5d9312f..755a559 100644
--- a/lti_consumer/plugin/views.py
+++ b/lti_consumer/plugin/views.py
@@ -6,7 +6,7 @@ from django.http import HttpResponse
 from django.views.decorators.csrf import csrf_exempt
 from django.views.decorators.http import require_http_methods
 
-from opaque_keys.edx.keys import UsageKey  # pylint: disable=import-error
+from opaque_keys.edx.keys import UsageKey
 from lms.djangoapps.courseware.module_render import (  # pylint: disable=import-error
     handle_xblock_callback,
     handle_xblock_callback_noauth,
diff --git a/lti_consumer/tests/unit/test_lti_xblock.py b/lti_consumer/tests/unit/test_lti_xblock.py
index 7a7faeb..7825c77 100644
--- a/lti_consumer/tests/unit/test_lti_xblock.py
+++ b/lti_consumer/tests/unit/test_lti_xblock.py
@@ -118,7 +118,7 @@ class TestProperties(TestLtiConsumerXBlock):
         """
         Test `context_id` returns unicode course id
         """
-        self.assertEqual(self.xblock.context_id, str(self.xblock.course_id))  # pylint: disable=no-member
+        self.assertEqual(self.xblock.context_id, str(self.xblock.course_id))
 
     def test_validate(self):
         """
@@ -227,7 +227,7 @@ class TestProperties(TestLtiConsumerXBlock):
         """
         self.assertEqual(
             self.xblock.resource_link_id,
-            "{}-{}".format(self.xblock.runtime.hostname, self.xblock.location.html_id())  # pylint: disable=no-member
+            "{}-{}".format(self.xblock.runtime.hostname, self.xblock.location.html_id())
         )
 
     @patch('lti_consumer.lti_xblock.LtiConsumerXBlock.context_id')
@@ -1110,7 +1110,7 @@ class TestProcessorSettings(TestLtiConsumerXBlock):
         with patch('lti_consumer.lti_xblock.LtiConsumerXBlock.get_settings', return_value=self.settings):
             processors = list(self.xblock.get_parameter_processors())
             assert len(processors) == 1, 'One processor should be enabled'
-            # pylint: disable=bad-option-value, comparison-with-callable
+            # pylint: disable=comparison-with-callable
             assert processors[0] == test_utils.dummy_processor, 'Should load the correct function'
 
     def test_disabled_processors(self):
diff --git a/lti_consumer/tests/unit/test_models.py b/lti_consumer/tests/unit/test_models.py
index 57e1f26..fa74094 100644
--- a/lti_consumer/tests/unit/test_models.py
+++ b/lti_consumer/tests/unit/test_models.py
@@ -54,12 +54,12 @@ class TestLtiCofigurationModel(TestCase):
 
         # Creates an LTI configuration objects for testing
         self.lti_1p1_config = LtiConfiguration.objects.create(
-            location=str(self.xblock.location),  # pylint: disable=no-member
+            location=str(self.xblock.location),
             version=LtiConfiguration.LTI_1P1
         )
 
         self.lti_1p3_config = LtiConfiguration.objects.create(
-            location=str(self.xblock.location),  # pylint: disable=no-member
+            location=str(self.xblock.location),
             version=LtiConfiguration.LTI_1P3
         )
 
diff --git a/lti_consumer/utils.py b/lti_consumer/utils.py
index 320b584..b1b7153 100644
--- a/lti_consumer/utils.py
+++ b/lti_consumer/utils.py
@@ -28,7 +28,7 @@ def get_lms_base():
     One possible improvement is to use `contentstore.get_lms_link_for_item`
     and strip the base domain name.
     """
-    return settings.LMS_ROOT_URL  # pragma: no cover
+    return settings.LMS_ROOT_URL
 
 
 def get_lms_lti_keyset_link(location):
diff --git a/setup.cfg b/setup.cfg
index 2489515..65a986d 100644
--- a/setup.cfg
+++ b/setup.cfg
@@ -1,4 +1,6 @@
 [pycodestyle]
-ignore = E501
+# W504 line break after binary operator
+# E722 do not use bare 'except' (pylint will tell us about that)
+ignore = E501, W504, E722
 max_line_length = 120
 exclude = settings
-- 
GitLab