From bbc386752f0e0b58f9b53bb9c9b130dc53157819 Mon Sep 17 00:00:00 2001 From: usamasadiq Date: Thu, 4 Feb 2021 16:55:33 +0500 Subject: [PATCH] Applied pylint-amnesty --- common/lib/capa/capa/capa_problem.py | 20 +- common/lib/capa/capa/checker.py | 20 +- common/lib/capa/capa/correctmap.py | 12 +- common/lib/capa/capa/customrender.py | 10 +- common/lib/capa/capa/inputtypes.py | 38 +-- common/lib/capa/capa/responsetypes.py | 114 ++++---- common/lib/capa/capa/safe_exec/lazymod.py | 4 +- .../capa/capa/safe_exec/tests/test_lazymod.py | 6 +- .../capa/safe_exec/tests/test_safe_exec.py | 8 +- common/lib/capa/capa/tests/helpers.py | 2 +- .../capa/capa/tests/response_xml_factory.py | 6 +- .../lib/capa/capa/tests/test_answer_pool.py | 6 +- .../lib/capa/capa/tests/test_capa_problem.py | 2 +- common/lib/capa/capa/tests/test_correctmap.py | 2 +- .../lib/capa/capa/tests/test_customrender.py | 6 +- .../lib/capa/capa/tests/test_html_render.py | 4 +- .../capa/capa/tests/test_input_templates.py | 30 +-- common/lib/capa/capa/tests/test_inputtypes.py | 40 +-- .../lib/capa/capa/tests/test_responsetypes.py | 24 +- common/lib/capa/capa/tests/test_shuffle.py | 4 +- .../capa/capa/tests/test_targeted_feedback.py | 2 +- common/lib/capa/capa/tests/test_util.py | 4 +- common/lib/capa/capa/xqueue_interface.py | 10 +- common/lib/capa/setup.py | 2 +- common/lib/safe_lxml/safe_lxml/__init__.py | 2 +- common/lib/safe_lxml/safe_lxml/etree.py | 4 +- common/lib/safe_lxml/setup.py | 2 +- common/lib/sandbox-packages/eia.py | 2 +- .../lib/sandbox-packages/loncapa/__init__.py | 4 +- .../sandbox-packages/loncapa/loncapa_check.py | 6 +- common/lib/sandbox-packages/setup.py | 2 +- .../verifiers/tests_draganddrop.py | 10 +- common/lib/symmath/setup.py | 2 +- common/lib/symmath/symmath/__init__.py | 3 +- common/lib/symmath/symmath/formula.py | 20 +- common/lib/symmath/symmath/symmath_check.py | 34 +-- common/lib/symmath/symmath/test_formula.py | 4 +- .../lib/symmath/symmath/test_symmath_check.py | 8 +- common/lib/xmodule/setup.py | 2 +- .../lib/xmodule/xmodule/annotatable_module.py | 12 +- common/lib/xmodule/xmodule/annotator_mixin.py | 2 +- .../xmodule/xmodule/assetstore/__init__.py | 4 +- .../xmodule/xmodule/assetstore/assetmgr.py | 6 +- .../assetstore/tests/test_asset_xml.py | 2 +- .../lib/xmodule/xmodule/backcompat_module.py | 6 +- common/lib/xmodule/xmodule/capa_base.py | 20 +- common/lib/xmodule/xmodule/capa_module.py | 18 +- .../lib/xmodule/xmodule/conditional_module.py | 10 +- .../xmodule/xmodule/contentstore/content.py | 26 +- .../xmodule/xmodule/contentstore/django.py | 4 +- .../lib/xmodule/xmodule/contentstore/mongo.py | 26 +- .../lib/xmodule/xmodule/contentstore/utils.py | 4 +- .../xmodule/xmodule/course_metadata_utils.py | 2 +- common/lib/xmodule/xmodule/course_module.py | 50 ++-- common/lib/xmodule/xmodule/editing_module.py | 16 +- common/lib/xmodule/xmodule/error_module.py | 2 +- common/lib/xmodule/xmodule/errortracker.py | 4 +- common/lib/xmodule/xmodule/exceptions.py | 12 +- common/lib/xmodule/xmodule/fields.py | 16 +- common/lib/xmodule/xmodule/graders.py | 8 +- common/lib/xmodule/xmodule/html_checker.py | 2 +- common/lib/xmodule/xmodule/html_module.py | 22 +- .../xmodule/xmodule/library_content_module.py | 6 +- common/lib/xmodule/xmodule/library_tools.py | 2 +- common/lib/xmodule/xmodule/lti_2_util.py | 8 +- common/lib/xmodule/xmodule/lti_module.py | 38 +-- common/lib/xmodule/xmodule/mako_module.py | 6 +- .../xmodule/xmodule/modulestore/__init__.py | 108 ++++---- .../lib/xmodule/xmodule/modulestore/django.py | 26 +- .../modulestore/draft_and_published.py | 4 +- .../xmodule/xmodule/modulestore/edit_info.py | 12 +- .../xmodule/xmodule/modulestore/exceptions.py | 14 +- .../xmodule/modulestore/inheritance.py | 24 +- .../lib/xmodule/xmodule/modulestore/mixed.py | 28 +- .../modulestore/modulestore_settings.py | 8 +- .../xmodule/xmodule/modulestore/mongo/base.py | 66 ++--- .../xmodule/modulestore/mongo/draft.py | 68 ++--- .../xmodule/modulestore/mongoengine_fields.py | 24 +- .../modulestore/perf_tests/generate_report.py | 8 +- .../perf_tests/test_asset_import_export.py | 16 +- .../lib/xmodule/xmodule/modulestore/search.py | 4 +- .../xmodule/modulestore/split_migrator.py | 6 +- .../modulestore/split_mongo/__init__.py | 4 +- .../split_mongo/caching_descriptor_system.py | 20 +- .../split_mongo/definition_lazy_loader.py | 2 +- .../split_mongo/mongo_connection.py | 10 +- .../xmodule/modulestore/split_mongo/split.py | 96 +++---- .../modulestore/split_mongo/split_draft.py | 104 ++++---- .../split_mongo/split_mongo_kvs.py | 10 +- .../xmodule/modulestore/store_utilities.py | 10 +- .../xmodule/modulestore/tests/django_utils.py | 12 +- .../xmodule/modulestore/tests/factories.py | 24 +- .../modulestore/tests/sample_courses.py | 8 +- .../modulestore/tests/test_assetstore.py | 20 +- .../modulestore/tests/test_contentstore.py | 10 +- .../test_cross_modulestore_import_export.py | 10 +- .../modulestore/tests/test_inheritance.py | 4 +- .../modulestore/tests/test_libraries.py | 2 +- .../tests/test_mixed_modulestore.py | 248 +++++++++--------- .../modulestore/tests/test_modulestore.py | 2 +- .../tests/test_modulestore_settings.py | 4 +- .../xmodule/modulestore/tests/test_mongo.py | 24 +- .../tests/test_mongo_call_count.py | 4 +- .../xmodule/modulestore/tests/test_publish.py | 30 +-- .../modulestore/tests/test_semantics.py | 2 +- .../modulestore/tests/test_split_migrator.py | 18 +- .../tests/test_split_modulestore.py | 32 +-- .../test_split_modulestore_bulk_operations.py | 38 +-- .../tests/test_split_w_old_mongo.py | 10 +- .../xmodule/modulestore/tests/test_xml.py | 4 +- .../modulestore/tests/test_xml_importer.py | 16 +- .../xmodule/modulestore/tests/utils.py | 12 +- common/lib/xmodule/xmodule/modulestore/xml.py | 44 ++-- .../xmodule/modulestore/xml_exporter.py | 6 +- .../xmodule/modulestore/xml_importer.py | 30 +-- common/lib/xmodule/xmodule/mongo_utils.py | 4 +- .../xmodule/xmodule/partitions/partitions.py | 18 +- .../xmodule/partitions/partitions_service.py | 2 +- .../partitions/tests/test_partitions.py | 14 +- common/lib/xmodule/xmodule/poll_module.py | 14 +- common/lib/xmodule/xmodule/progress.py | 2 +- .../lib/xmodule/xmodule/randomize_module.py | 2 +- common/lib/xmodule/xmodule/raw_module.py | 16 +- common/lib/xmodule/xmodule/seq_module.py | 28 +- .../lib/xmodule/xmodule/split_test_module.py | 18 +- common/lib/xmodule/xmodule/static_content.py | 8 +- common/lib/xmodule/xmodule/stringify.py | 2 +- common/lib/xmodule/xmodule/tabs.py | 26 +- common/lib/xmodule/xmodule/template_module.py | 2 +- common/lib/xmodule/xmodule/tests/__init__.py | 22 +- common/lib/xmodule/xmodule/tests/helpers.py | 2 +- .../xmodule/xmodule/tests/rendering/core.py | 12 +- .../xmodule/tests/test_annotatable_module.py | 22 +- .../xmodule/xmodule/tests/test_capa_module.py | 24 +- .../xmodule/xmodule/tests/test_conditional.py | 26 +- .../lib/xmodule/xmodule/tests/test_content.py | 4 +- .../tests/test_course_metadata_utils.py | 4 +- .../xmodule/tests/test_course_module.py | 20 +- .../tests/test_delay_between_attempts.py | 10 +- .../xmodule/tests/test_editing_module.py | 2 +- .../xmodule/tests/test_error_module.py | 16 +- .../lib/xmodule/xmodule/tests/test_export.py | 14 +- .../lib/xmodule/xmodule/tests/test_fields.py | 8 +- .../lib/xmodule/xmodule/tests/test_graders.py | 2 +- .../xmodule/xmodule/tests/test_html_module.py | 4 +- .../lib/xmodule/xmodule/tests/test_import.py | 12 +- .../xmodule/tests/test_import_static.py | 2 +- .../xmodule/tests/test_library_content.py | 6 +- .../tests/test_library_sourced_block.py | 6 +- .../xmodule/xmodule/tests/test_lti20_unit.py | 8 +- .../xmodule/xmodule/tests/test_lti_unit.py | 4 +- .../xmodule/xmodule/tests/test_progress.py | 2 +- .../xmodule/xmodule/tests/test_sequence.py | 6 +- .../xmodule/xmodule/tests/test_services.py | 12 +- .../xmodule/tests/test_split_test_module.py | 6 +- .../xmodule/xmodule/tests/test_vertical.py | 2 +- .../lib/xmodule/xmodule/tests/test_video.py | 8 +- .../xmodule/tests/test_xblock_wrappers.py | 14 +- .../xmodule/xmodule/tests/test_xml_module.py | 18 +- .../lib/xmodule/xmodule/tests/xml/__init__.py | 2 +- .../xmodule/xmodule/tests/xml/factories.py | 2 +- common/lib/xmodule/xmodule/timeinfo.py | 2 +- common/lib/xmodule/xmodule/unit_block.py | 2 +- common/lib/xmodule/xmodule/util/sandboxing.py | 2 +- common/lib/xmodule/xmodule/validation.py | 10 +- common/lib/xmodule/xmodule/vertical_block.py | 16 +- .../xmodule/xmodule/video_module/__init__.py | 2 +- .../xmodule/video_module/transcripts_utils.py | 16 +- .../xmodule/video_module/video_handlers.py | 16 +- .../xmodule/video_module/video_module.py | 38 +-- .../xmodule/video_module/video_xfields.py | 2 +- .../lib/xmodule/xmodule/word_cloud_module.py | 4 +- common/lib/xmodule/xmodule/wrapper_module.py | 4 +- common/lib/xmodule/xmodule/x_module.py | 92 +++---- common/lib/xmodule/xmodule/xml_module.py | 26 +- 175 files changed, 1396 insertions(+), 1395 deletions(-) diff --git a/common/lib/capa/capa/capa_problem.py b/common/lib/capa/capa/capa_problem.py index 713222d322..7a2408e209 100644 --- a/common/lib/capa/capa/capa_problem.py +++ b/common/lib/capa/capa/capa_problem.py @@ -435,7 +435,7 @@ class LoncapaProblem(object): # if answers include File objects, convert them to filenames. self.student_answers = convert_files_to_filenames(answers) new_cmap = self.get_grade_from_current_answers(answers) - self.correct_map = new_cmap + self.correct_map = new_cmap # lint-amnesty, pylint: disable=attribute-defined-outside-init return self.correct_map def supports_rescoring(self): @@ -506,7 +506,7 @@ class LoncapaProblem(object): """ # dict of (id, correct_answer) answer_map = dict() - for response in self.responders.keys(): + for response in self.responders.keys(): # lint-amnesty, pylint: disable=consider-iterating-dictionary results = self.responder_answers[response] answer_map.update(results) @@ -526,7 +526,7 @@ class LoncapaProblem(object): get_question_answers may only return a subset of these. """ answer_ids = [] - for response in self.responders.keys(): + for response in self.responders.keys(): # lint-amnesty, pylint: disable=consider-iterating-dictionary results = self.responder_answers[response] answer_ids.append(list(results.keys())) return answer_ids @@ -809,7 +809,7 @@ class LoncapaProblem(object): try: # open using LoncapaSystem OSFS filestore ifp = self.capa_system.filestore.open(filename) - except Exception as err: + except Exception as err: # lint-amnesty, pylint: disable=broad-except log.warning( 'Error %s in problem xml include: %s', err, @@ -820,14 +820,14 @@ class LoncapaProblem(object): ) # if debugging, don't fail - just log error # TODO (vshnayder): need real error handling, display to users - if not self.capa_system.DEBUG: + if not self.capa_system.DEBUG: # lint-amnesty, pylint: disable=no-else-raise raise else: continue try: # read in and convert to XML incxml = etree.XML(ifp.read()) - except Exception as err: + except Exception as err: # lint-amnesty, pylint: disable=broad-except log.warning( 'Error %s in problem xml include: %s', err, @@ -836,7 +836,7 @@ class LoncapaProblem(object): log.warning('Cannot parse XML in %s', (filename)) # if debugging, don't fail - just log error # TODO (vshnayder): same as above - if not self.capa_system.DEBUG: + if not self.capa_system.DEBUG: # lint-amnesty, pylint: disable=no-else-raise raise else: continue @@ -864,7 +864,7 @@ class LoncapaProblem(object): # find additional comma-separated modules search path path = [] - for dir in raw_path: + for dir in raw_path: # lint-amnesty, pylint: disable=redefined-builtin if not dir: continue @@ -937,7 +937,7 @@ class LoncapaProblem(object): unsafely=self.capa_system.can_execute_unsafe_code(), ) except Exception as err: - log.exception("Error while execing script code: " + all_code) + log.exception("Error while execing script code: " + all_code) # lint-amnesty, pylint: disable=logging-not-lazy msg = Text("Error while executing script code: %s" % str(err)) raise responsetypes.LoncapaProblemError(msg) @@ -1111,7 +1111,7 @@ class LoncapaProblem(object): # get responder answers (do this only once, since there may be a performance cost, # eg with externalresponse) self.responder_answers = {} - for response in self.responders.keys(): + for response in self.responders.keys(): # lint-amnesty, pylint: disable=consider-iterating-dictionary try: self.responder_answers[response] = self.responders[response].get_answers() except: diff --git a/common/lib/capa/capa/checker.py b/common/lib/capa/capa/checker.py index b575c4aec2..872e9bf9d2 100755 --- a/common/lib/capa/capa/checker.py +++ b/common/lib/capa/capa/checker.py @@ -19,7 +19,7 @@ logging.basicConfig(format="%(levelname)s %(message)s") log = logging.getLogger('capa.checker') -class DemoSystem(object): +class DemoSystem(object): # lint-amnesty, pylint: disable=missing-class-docstring def __init__(self): self.lookup = TemplateLookup(directories=[path(__file__).dirname() / 'templates']) self.DEBUG = True @@ -31,7 +31,7 @@ class DemoSystem(object): return self.lookup.get_template(template_filename).render(**dictionary) -def main(): +def main(): # lint-amnesty, pylint: disable=missing-function-docstring parser = argparse.ArgumentParser(description='Check Problem Files') parser.add_argument("command", choices=['test', 'show']) # Watch? Render? Open? parser.add_argument("files", nargs="+", type=argparse.FileType('r')) @@ -49,8 +49,8 @@ def main(): log.info("Opening {0}".format(problem_file.name)) try: - problem = LoncapaProblem(problem_file, "fakeid", seed=args.seed, system=system) - except Exception as ex: + problem = LoncapaProblem(problem_file, "fakeid", seed=args.seed, system=system) # lint-amnesty, pylint: disable=no-value-for-parameter, unexpected-keyword-arg + except Exception as ex: # lint-amnesty, pylint: disable=broad-except log.error("Could not parse file {0}".format(problem_file.name)) log.exception(ex) continue @@ -70,7 +70,7 @@ def command_show(problem): print(problem.get_html()) -def command_test(problem): +def command_test(problem): # lint-amnesty, pylint: disable=missing-function-docstring # We're going to trap stdout/stderr from the problems (yes, some print) old_stdout, old_stderr = sys.stdout, sys.stderr try: @@ -84,7 +84,7 @@ def command_test(problem): "captured stdout from {0}".format(problem)) log_captured_output(sys.stderr, "captured stderr from {0}".format(problem)) - except Exception as e: + except Exception as e: # lint-amnesty, pylint: disable=broad-except log.exception(e) finally: sys.stdout, sys.stderr = old_stdout, old_stderr @@ -135,7 +135,7 @@ def check_that_suggested_answers_work(problem): assert(all(result == 'correct' for answer_id, result in real_results.items())) except UndefinedVariable as uv_exc: - log.error("The variable \"{0}\" specified in the ".format(uv_exc) + + log.error("The variable \"{0}\" specified in the ".format(uv_exc) + # lint-amnesty, pylint: disable=logging-not-lazy "solution isn't recognized (is it a units measure?).") except AssertionError: log.error("The following generated answers were not accepted for {0}:" @@ -143,16 +143,16 @@ def check_that_suggested_answers_work(problem): for question_id, result in sorted(real_results.items()): if result != 'correct': log.error(" {0} = {1}".format(question_id, real_answers[question_id])) - except Exception as ex: + except Exception as ex: # lint-amnesty, pylint: disable=broad-except log.error("Uncaught error in {0}".format(problem)) log.exception(ex) -def log_captured_output(output_stream, stream_name): +def log_captured_output(output_stream, stream_name): # lint-amnesty, pylint: disable=missing-function-docstring output_stream.seek(0) output_text = output_stream.read() if output_text: - log.info("##### Begin {0} #####\n".format(stream_name) + output_text) + log.info("##### Begin {0} #####\n".format(stream_name) + output_text) # lint-amnesty, pylint: disable=logging-not-lazy log.info("##### End {0} #####".format(stream_name)) diff --git a/common/lib/capa/capa/correctmap.py b/common/lib/capa/capa/correctmap.py index 85376fb526..07ae3f9659 100644 --- a/common/lib/capa/capa/correctmap.py +++ b/common/lib/capa/capa/correctmap.py @@ -1,4 +1,4 @@ -# ----------------------------------------------------------------------------- +# ----------------------------------------------------------------------------- # lint-amnesty, pylint: disable=missing-module-docstring # class used to store graded responses to CAPA questions # # Used by responsetypes and capa_problem @@ -38,8 +38,8 @@ class CorrectMap(object): return self.cmap.__iter__() # See the documentation for 'set_dict' for the use of kwargs - def set( - self, + def set( # lint-amnesty, pylint: disable=missing-function-docstring + self, # lint-amnesty, pylint: disable=unused-argument answer_id=None, correctness=None, npoints=None, @@ -47,7 +47,7 @@ class CorrectMap(object): hint='', hintmode=None, queuestate=None, - answervariable=None, # pylint: disable=C0330 + answervariable=None, # lint-amnesty, pylint: disable=C0330, bad-option-value **kwargs ): @@ -144,13 +144,13 @@ class CorrectMap(object): # if not correct and no points have been assigned, return 0 return 0 - def set_property(self, answer_id, property, value): + def set_property(self, answer_id, property, value): # lint-amnesty, pylint: disable=redefined-builtin if answer_id in self.cmap: self.cmap[answer_id][property] = value else: self.cmap[answer_id] = {property: value} - def get_property(self, answer_id, property, default=None): + def get_property(self, answer_id, property, default=None): # lint-amnesty, pylint: disable=redefined-builtin if answer_id in self.cmap: return self.cmap[answer_id].get(property, default) return default diff --git a/common/lib/capa/capa/customrender.py b/common/lib/capa/capa/customrender.py index 9615abbaa5..4d4669bf6d 100644 --- a/common/lib/capa/capa/customrender.py +++ b/common/lib/capa/capa/customrender.py @@ -24,7 +24,7 @@ registry = TagRegistry() # ----------------------------------------------------------------------------- -class MathRenderer(object): +class MathRenderer(object): # lint-amnesty, pylint: disable=missing-class-docstring tags = ['math'] def __init__(self, system, xml): @@ -57,11 +57,11 @@ class MathRenderer(object): """ # TODO: why are there nested html tags here?? Why are there html tags at all, in fact? # xss-lint: disable=python-interpolate-html - html = '%s%s' % ( + html = '%s%s' % ( # lint-amnesty, pylint: disable=redefined-outer-name self.mathstr, saxutils.escape(self.xml.tail)) try: xhtml = etree.XML(html) - except Exception as err: + except Exception as err: # lint-amnesty, pylint: disable=broad-except if self.system.DEBUG: # xss-lint: disable=python-interpolate-html msg = '

Error %s

' % ( @@ -99,7 +99,7 @@ class SolutionRenderer(object): def get_html(self): context = {'id': self.id} - html = self.system.render_template("solutionspan.html", context) + html = self.system.render_template("solutionspan.html", context) # lint-amnesty, pylint: disable=redefined-outer-name return etree.XML(html) @@ -175,7 +175,7 @@ class ClarificationRenderer(object): Return the contents of this tag, rendered to html, as an etree element. """ context = {'clarification': self.inner_html} - html = self.system.render_template("clarification.html", context) + html = self.system.render_template("clarification.html", context) # lint-amnesty, pylint: disable=redefined-outer-name xml = etree.XML(html) # We must include any text that was following our original ... XML node.: xml.tail = self.tail diff --git a/common/lib/capa/capa/inputtypes.py b/common/lib/capa/capa/inputtypes.py index be20cdd9f9..b18beec8e3 100644 --- a/common/lib/capa/capa/inputtypes.py +++ b/common/lib/capa/capa/inputtypes.py @@ -254,7 +254,7 @@ class InputTypeBase(object): # super().__init__, and are isolated from changes to the input # constructor interface. self.setup() - except Exception as err: + except Exception as err: # lint-amnesty, pylint: disable=broad-except # Something went wrong: add xml to message, but keep the traceback msg = u"Error in xml '{x}': {err} ".format( x=etree.tostring(xml), err=text_type(err)) @@ -298,7 +298,7 @@ class InputTypeBase(object): If this method raises an exception, it will be wrapped with a message that includes the problem xml. """ - pass + pass # lint-amnesty, pylint: disable=unnecessary-pass def handle_ajax(self, dispatch, data): """ @@ -311,7 +311,7 @@ class InputTypeBase(object): Output: a dictionary object that can be serialized into JSON. This will be sent back to the Javascript. """ - pass + pass # lint-amnesty, pylint: disable=unnecessary-pass def _get_render_context(self): """ @@ -384,11 +384,11 @@ class InputTypeBase(object): output = etree.XML(html) except etree.XMLSyntaxError as ex: # If `html` contains attrs with no values, like `controls` in