From ab4c14afe3d134d3abe6877c141ba61db53f4583 Mon Sep 17 00:00:00 2001 From: Usama Sadiq Date: Wed, 20 Oct 2021 16:28:18 +0500 Subject: [PATCH] fix: fix pylint warnings (#29049) --- cms/djangoapps/contentstore/views/component.py | 2 +- cms/djangoapps/contentstore/views/course.py | 2 +- cms/djangoapps/contentstore/views/library.py | 2 +- cms/djangoapps/course_creators/models.py | 2 +- common/djangoapps/terrain/stubs/http.py | 2 +- common/djangoapps/terrain/stubs/youtube.py | 2 +- common/djangoapps/util/date_utils.py | 2 +- common/djangoapps/util/models.py | 4 ++-- common/lib/symmath/symmath/symmath_check.py | 2 +- common/lib/xmodule/xmodule/course_module.py | 4 ++-- common/lib/xmodule/xmodule/modulestore/xml_importer.py | 2 +- common/lib/xmodule/xmodule/tabs.py | 2 +- 12 files changed, 14 insertions(+), 14 deletions(-) diff --git a/cms/djangoapps/contentstore/views/component.py b/cms/djangoapps/contentstore/views/component.py index db965ea2d9..7bad84765c 100644 --- a/cms/djangoapps/contentstore/views/component.py +++ b/cms/djangoapps/contentstore/views/component.py @@ -405,7 +405,7 @@ def get_component_templates(courselike, library=False): # lint-amnesty, pylint: # Set component types according to course policy file if isinstance(course_advanced_keys, list): for category in course_advanced_keys: - if category in advanced_component_types.keys() and category not in categories: + if category in advanced_component_types.keys() and category not in categories: # pylint: disable=consider-iterating-dictionary # boilerplates not supported for advanced components try: component_display_name = xblock_type_display_name(category, default_display_name=category) diff --git a/cms/djangoapps/contentstore/views/course.py b/cms/djangoapps/contentstore/views/course.py index 52e1c13db9..d9feb4301e 100644 --- a/cms/djangoapps/contentstore/views/course.py +++ b/cms/djangoapps/contentstore/views/course.py @@ -916,7 +916,7 @@ def _create_or_rerun_course(request): return JsonResponse({ "ErrMsg": _("Unable to create course '{name}'.\n\n{err}").format(name=display_name, err=str(error))} ) - except PermissionDenied as error: + except PermissionDenied as error: # pylint: disable=unused-variable log.info( "User does not have the permission to create course in this organization" "or course creation is disabled." diff --git a/cms/djangoapps/contentstore/views/library.py b/cms/djangoapps/contentstore/views/library.py index b065e3e4cd..c3d4c1fde9 100644 --- a/cms/djangoapps/contentstore/views/library.py +++ b/cms/djangoapps/contentstore/views/library.py @@ -208,7 +208,7 @@ def _create_library(request): ) # Give the user admin ("Instructor") role for this library: add_instructor(new_lib.location.library_key, request.user, request.user) - except PermissionDenied as error: + except PermissionDenied as error: # pylint: disable=unused-variable log.info( "User does not have the permission to create LIBRARY in this organization." "User: '%s' Org: '%s' LIBRARY #: '%s'.", diff --git a/cms/djangoapps/course_creators/models.py b/cms/djangoapps/course_creators/models.py index 9940ee026c..d48484b94d 100644 --- a/cms/djangoapps/course_creators/models.py +++ b/cms/djangoapps/course_creators/models.py @@ -79,7 +79,7 @@ def post_save_callback(sender, **kwargs): # We need to keep track of all_organization switch. If this switch is changed we are going to remove the # Course Creator group. if instance.state != instance.orig_state or instance.all_organizations != instance.orig_all_organizations: - granted_state_change = instance.state == CourseCreator.GRANTED or instance.orig_state == CourseCreator.GRANTED + granted_state_change = instance.state == CourseCreator.GRANTED or instance.orig_state == CourseCreator.GRANTED # pylint: disable=consider-using-in # If either old or new state is 'granted', we must manipulate the course creator # group maintained by authz. That requires staff permissions (stored admin). if granted_state_change: diff --git a/common/djangoapps/terrain/stubs/http.py b/common/djangoapps/terrain/stubs/http.py index a0730b594d..ba00c97f1e 100644 --- a/common/djangoapps/terrain/stubs/http.py +++ b/common/djangoapps/terrain/stubs/http.py @@ -154,7 +154,7 @@ class StubHttpRequestHandler(BaseHTTPRequestHandler): Each POST parameter is the configuration key. Each POST value is a JSON-encoded string value for the configuration. """ - if self.path == "/set_config" or self.path == "/set_config/": + if self.path in ("/set_config", "/set_config/"): if len(self.post_dict) > 0: for key, value in self.post_dict.items(): diff --git a/common/djangoapps/terrain/stubs/youtube.py b/common/djangoapps/terrain/stubs/youtube.py index e054d87420..67cac950f9 100644 --- a/common/djangoapps/terrain/stubs/youtube.py +++ b/common/djangoapps/terrain/stubs/youtube.py @@ -40,7 +40,7 @@ class StubYouTubeHandler(StubHttpRequestHandler): """ Allow callers to delete all the server configurations using the /del_config URL. """ - if self.path == "/del_config" or self.path == "/del_config/": + if self.path in ("/del_config", "/del_config/"): self.server.config = {} self.log_message("Reset Server Configuration.") self.send_response(200) diff --git a/common/djangoapps/util/date_utils.py b/common/djangoapps/util/date_utils.py index be2b859bf7..5145057174 100644 --- a/common/djangoapps/util/date_utils.py +++ b/common/djangoapps/util/date_utils.py @@ -236,7 +236,7 @@ def strftime_localized_html(dtime, fmt): format_mapping = { 'SHORT_DATE': 'shortDate', } - assert fmt in format_mapping.keys(), 'format "%s" not yet supported in strftime_localized_html' % fmt + assert fmt in format_mapping.keys(), 'format "%s" not yet supported in strftime_localized_html' % fmt # pylint: disable=consider-iterating-dictionary date_html = '{formatted_date_localized}' diff --git a/common/djangoapps/util/models.py b/common/djangoapps/util/models.py index ef6d4c0cb2..1959ac3d7c 100644 --- a/common/djangoapps/util/models.py +++ b/common/djangoapps/util/models.py @@ -35,7 +35,7 @@ def decompress_string(value): """ try: - val = value.encode('utf').decode('base64') # lint-amnesty, pylint: disable=invalid-str-codec + val = value.encode('utf').decode('base64') # pylint: disable=invalid-str-codec zbuf = BytesIO(val) zfile = gzip.GzipFile(fileobj=zbuf) ret = zfile.read() @@ -60,7 +60,7 @@ class CompressedTextField(CreatorMixin, models.TextField): if isinstance(value, str): value = value.encode('utf8') value = compress_string(value) - value = value.encode('base64').decode('utf8') # lint-amnesty, pylint: disable=invalid-str-codec + value = value.encode('base64').decode('utf8') # pylint: disable=invalid-str-codec return value def to_python(self, value): diff --git a/common/lib/symmath/symmath/symmath_check.py b/common/lib/symmath/symmath/symmath_check.py index 5e32527858..ffd56c8922 100644 --- a/common/lib/symmath/symmath/symmath_check.py +++ b/common/lib/symmath/symmath/symmath_check.py @@ -229,7 +229,7 @@ def symmath_check(expect, ans, dynamath=None, options=None, debug=None, xml=None # if expected answer is a number, try parsing provided answer as a number also try: fans = my_sympify(str(ans), matrix=do_matrix, do_qubit=do_qubit) - except Exception as err: # lint-amnesty, pylint: disable=broad-except + except Exception as err: # lint-amnesty, pylint: disable=broad-except, unused-variable fans = None # do a numerical comparison if both expected and answer are numbers diff --git a/common/lib/xmodule/xmodule/course_module.py b/common/lib/xmodule/xmodule/course_module.py index 8fb6899a6a..7b6bcfb9ad 100644 --- a/common/lib/xmodule/xmodule/course_module.py +++ b/common/lib/xmodule/xmodule/course_module.py @@ -103,7 +103,7 @@ edx_xml_parser = etree.XMLParser(dtd_validation=False, load_dtd=False, _cached_toc = {} -class Textbook: # lint-amnesty, pylint: disable=missing-class-docstring,eq-without-hash +class Textbook: # lint-amnesty, pylint: disable=missing-class-docstring, eq-without-hash def __init__(self, title, book_url): self.title = title self.book_url = book_url @@ -146,7 +146,7 @@ class Textbook: # lint-amnesty, pylint: disable=missing-class-docstring,eq-with # expire every 10 minutes if age.seconds < 600: return table_of_contents - except Exception as err: # lint-amnesty, pylint: disable=broad-except + except Exception as err: # lint-amnesty, pylint: disable=broad-except, unused-variable pass # Get the table of contents from S3 diff --git a/common/lib/xmodule/xmodule/modulestore/xml_importer.py b/common/lib/xmodule/xmodule/modulestore/xml_importer.py index a45cb7df5f..f3fb90bfaa 100644 --- a/common/lib/xmodule/xmodule/modulestore/xml_importer.py +++ b/common/lib/xmodule/xmodule/modulestore/xml_importer.py @@ -647,7 +647,7 @@ class CourseImportManager(ImportManager): courselike_key.course, courselike_key.run ) - if course.wiki_slug == original_unique_wiki_slug or course.wiki_slug == courselike_key.course: + if course.wiki_slug in (original_unique_wiki_slug, courselike_key.course): course.wiki_slug = '{}.{}.{}'.format( course.id.org, course.id.course, diff --git a/common/lib/xmodule/xmodule/tabs.py b/common/lib/xmodule/xmodule/tabs.py index 91c319d71c..5ebe9b0095 100644 --- a/common/lib/xmodule/xmodule/tabs.py +++ b/common/lib/xmodule/xmodule/tabs.py @@ -422,7 +422,7 @@ class CourseTabList(List): # find one of the discussion tab types in the course tabs for tab in course.tabs: - if tab.type == 'discussion' or tab.type == 'external_discussion': + if tab.type in ('discussion', 'external_discussion'): return tab return None