diff --git a/course/content.py b/course/content.py index 7ab613bd2c4a64f30f4eebb5f3b66af694d26ae2..bbca3e5b3f8f7fc3de43f23766d53414fcd5fae3 100644 --- a/course/content.py +++ b/course/content.py @@ -403,34 +403,34 @@ def process_yaml_for_expansion(yaml_str): line_count = len(lines) while i < line_count: - l = lines[i].rstrip() - yaml_block_scalar_match = YAML_BLOCK_START_SCALAR_RE.search(l) + ln = lines[i].rstrip() + yaml_block_scalar_match = YAML_BLOCK_START_SCALAR_RE.search(ln) if yaml_block_scalar_match is not None: unprocessed_block_lines = [] allow_jinja = bool(yaml_block_scalar_match.group(2)) - l = YAML_BLOCK_START_SCALAR_RE.sub( - r"\1\3", l) + ln = YAML_BLOCK_START_SCALAR_RE.sub( + r"\1\3", ln) - unprocessed_block_lines.append(l) + unprocessed_block_lines.append(ln) - block_start_indent = len(LEADING_SPACES_RE.match(l).group(1)) + block_start_indent = len(LEADING_SPACES_RE.match(ln).group(1)) i += 1 while i < line_count: - l = lines[i] + ln = lines[i] - if not l.rstrip(): - unprocessed_block_lines.append(l) + if not ln.rstrip(): + unprocessed_block_lines.append(ln) i += 1 continue - line_indent = len(LEADING_SPACES_RE.match(l).group(1)) + line_indent = len(LEADING_SPACES_RE.match(ln).group(1)) if line_indent <= block_start_indent: break else: - unprocessed_block_lines.append(l.rstrip()) + unprocessed_block_lines.append(ln.rstrip()) i += 1 if not allow_jinja: @@ -439,14 +439,14 @@ def process_yaml_for_expansion(yaml_str): if not allow_jinja: jinja_lines.append("{% endraw %}") - elif GROUP_COMMENT_START.match(l): + elif GROUP_COMMENT_START.match(ln): jinja_lines.append("{% raw %}") - jinja_lines.append(l) + jinja_lines.append(ln) jinja_lines.append("{% endraw %}") i += 1 else: - jinja_lines.append(l) + jinja_lines.append(ln) i += 1 return "\n".join(jinja_lines) @@ -966,8 +966,8 @@ def extract_title_from_markup(markup_text): # type: (Text) -> Optional[Text] lines = markup_text.split("\n") - for l in lines[:10]: - match = TITLE_RE.match(l) + for ln in lines[:10]: + match = TITLE_RE.match(ln) if match is not None: return match.group(1) diff --git a/course/enrollment.py b/course/enrollment.py index c688024c00e62bab7cb2fb62daf771ac0fbbb845..4d0dc8d6dd7cbf5f4797b1999bc861393efb8054 100644 --- a/course/enrollment.py +++ b/course/enrollment.py @@ -473,27 +473,27 @@ def create_preapprovals(pctx): pending_approved_count = 0 roles = form.cleaned_data["roles"] - for l in form.cleaned_data["preapproval_data"].split("\n"): - l = l.strip() + for ln in form.cleaned_data["preapproval_data"].split("\n"): + ln = ln.strip() preapp_type = form.cleaned_data["preapproval_type"] - if not l: + if not ln: continue if preapp_type == "email": try: preapproval = ParticipationPreapproval.objects.get( - email__iexact=l, + email__iexact=ln, course=pctx.course) except ParticipationPreapproval.DoesNotExist: - # approve if l is requesting enrollment + # approve if ln is requesting enrollment try: pending = Participation.objects.get( course=pctx.course, status=participation_status.requested, - user__email__iexact=l) + user__email__iexact=ln) except Participation.DoesNotExist: pass @@ -511,7 +511,7 @@ def create_preapprovals(pctx): continue preapproval = ParticipationPreapproval() - preapproval.email = l + preapproval.email = ln preapproval.course = pctx.course preapproval.creator = request.user preapproval.save() @@ -523,16 +523,16 @@ def create_preapprovals(pctx): try: preapproval = ParticipationPreapproval.objects.get( - course=pctx.course, institutional_id__iexact=l) + course=pctx.course, institutional_id__iexact=ln) except ParticipationPreapproval.DoesNotExist: - # approve if l is requesting enrollment + # approve if ln is requesting enrollment try: pending = Participation.objects.get( course=pctx.course, status=participation_status.requested, - user__institutional_id__iexact=l) + user__institutional_id__iexact=ln) if ( pctx.course.preapproval_require_verified_inst_id and not pending.user.institutional_id_verified): @@ -553,7 +553,7 @@ def create_preapprovals(pctx): continue preapproval = ParticipationPreapproval() - preapproval.institutional_id = l + preapproval.institutional_id = ln preapproval.course = pctx.course preapproval.creator = request.user preapproval.save() diff --git a/course/page/choice.py b/course/page/choice.py index edaa2ee9610c1d4a21052e14fbd57d17b103aa8f..fb3ebd22e32e5913aca5b8a0916b6eec78e91afb 100644 --- a/course/page/choice.py +++ b/course/page/choice.py @@ -94,7 +94,7 @@ class ChoiceQuestionBase(PageBaseWithTitle, PageBaseWithValue): for choice_idx, choice in enumerate(page_desc.choices): try: choice = str(choice) - except: + except Exception: raise ValidationError( string_concat( "%(location)s, ", @@ -653,7 +653,7 @@ class SurveyChoiceQuestion(PageBaseWithTitle): for choice_idx, choice in enumerate(page_desc.choices): try: choice = str(choice) - except: + except Exception: raise ValidationError( string_concat( "%(location)s, ", diff --git a/course/page/code.py b/course/page/code.py index 4bacfea386678bf3efe16504ad4759bee3fa5551..c872326148ee04c741971760910a6960fb960905 100644 --- a/course/page/code.py +++ b/course/page/code.py @@ -627,7 +627,7 @@ class PythonCodeQuestion(PageBaseWithTitle, PageBaseWithValue): try: response_dict = request_python_run_with_retries(run_req, run_timeout=self.page_desc.timeout) - except: + except Exception: from traceback import format_exc response_dict = { "result": "uncaught_error", diff --git a/course/page/code_runpy_backend.py b/course/page/code_runpy_backend.py index 8e3d2ff79dcfbfb9b34316865604ca950bd51323..d7d1a7f72a911a48a8897976c97488e6d003d3e3 100644 --- a/course/page/code_runpy_backend.py +++ b/course/page/code_runpy_backend.py @@ -176,7 +176,7 @@ def run_code(result, run_req): try: setup_code = compile( run_req.setup_code, "[setup code]", 'exec') - except: + except Exception: package_exception(result, "setup_compile_error") return else: @@ -185,7 +185,7 @@ def run_code(result, run_req): try: user_code = compile( run_req.user_code, "[user code]", 'exec') - except: + except Exception: package_exception(result, "user_compile_error") return @@ -193,7 +193,7 @@ def run_code(result, run_req): try: test_code = compile( run_req.test_code, "[test code]", 'exec') - except: + except Exception: package_exception(result, "test_compile_error") return else: @@ -231,7 +231,7 @@ def run_code(result, run_req): if setup_code is not None: try: exec(setup_code, maint_ctx) - except: + except Exception: package_exception(result, "setup_error") return @@ -249,7 +249,7 @@ def run_code(result, run_req): try: exec(user_code, user_ctx) - except: + except Exception: package_exception(result, "user_error") return @@ -269,7 +269,7 @@ def run_code(result, run_req): bio = BytesIO() try: pt.savefig(bio, format=format) - except: + except Exception: pass else: figures.append( @@ -294,7 +294,7 @@ def run_code(result, run_req): exec(test_code, maint_ctx) except GradingComplete: pass - except: + except Exception: package_exception(result, "test_error") return diff --git a/course/page/inline.py b/course/page/inline.py index 5c883f65e651c796fc450820704c57c1ec2d3d08..3361ebe9e9fbbe8eda7eff1a043ae14e2f056755 100644 --- a/course/page/inline.py +++ b/course/page/inline.py @@ -414,7 +414,7 @@ class ChoicesAnswer(AnswerBase): for choice_idx, choice in enumerate(answers_desc.choices): try: choice = str(choice) - except: + except Exception: raise ValidationError( string_concat( "%(location)s: '%(answer_name)s' ", diff --git a/course/page/text.py b/course/page/text.py index 472f4fed25e96b31a415b4a8b2f0c3d5ae68ac96..f568ceb236684542398c7006db9213bf02ccc6d2 100644 --- a/course/page/text.py +++ b/course/page/text.py @@ -156,7 +156,7 @@ class RELATEPageValidator(object): raise ValidationError(ugettext("page must be of type '%s'") % self.validator_desc.page_type) - except: + except Exception: tp, e, _ = sys.exc_info() raise forms.ValidationError("%(err_type)s: %(err_str)s" @@ -279,7 +279,7 @@ class RegexMatcher(TextAnswerMatcher): def __init__(self, vctx, location, pattern): try: self.pattern = re.compile(pattern, self.re_flags) - except: + except Exception: tp, e, _ = sys.exc_info() raise ValidationError( @@ -349,7 +349,7 @@ class SymbolicExpressionMatcher(TextAnswerMatcher): "err_str": str(e) }) - except: + except Exception: tp, e, _ = sys.exc_info() raise ValidationError( "%(location)s: %(err_type)s: %(err_str)s" @@ -362,7 +362,7 @@ class SymbolicExpressionMatcher(TextAnswerMatcher): def validate(self, s): try: parse_sympy(s) - except: + except Exception: tp, e, _ = sys.exc_info() raise forms.ValidationError("%(err_type)s: %(err_str)s" % {"err_type": tp.__name__, "err_str": str(e)}) @@ -410,7 +410,7 @@ def float_or_sympy_evalf(s): def _is_valid_float(s): try: float_or_sympy_evalf(s) - except: + except Exception: return False else: return True @@ -441,7 +441,7 @@ class FloatMatcher(TextAnswerMatcher): try: self.matcher_desc.value = \ float_or_sympy_evalf(matcher_desc.value) - except: + except Exception: raise ValidationError( string_concat( "%s: 'value' ", @@ -452,7 +452,7 @@ class FloatMatcher(TextAnswerMatcher): try: self.matcher_desc.rtol = \ float_or_sympy_evalf(matcher_desc.rtol) - except: + except Exception: raise ValidationError( string_concat( "%s: 'rtol' ", @@ -470,7 +470,7 @@ class FloatMatcher(TextAnswerMatcher): try: self.matcher_desc.atol = \ float_or_sympy_evalf(matcher_desc.atol) - except: + except Exception: raise ValidationError( string_concat( "%s: 'atol' ", @@ -497,7 +497,7 @@ class FloatMatcher(TextAnswerMatcher): def validate(self, s): try: float_or_sympy_evalf(s) - except: + except Exception: tp, e, _ = sys.exc_info() raise forms.ValidationError("%(err_type)s: %(err_str)s" % {"err_type": tp.__name__, "err_str": str(e)}) diff --git a/course/sandbox.py b/course/sandbox.py index 23258395ed0638fdadba1757bf4824a8019920d2..18a7cdbd9196ae761711ad6b323977a4f8592628 100644 --- a/course/sandbox.py +++ b/course/sandbox.py @@ -125,7 +125,7 @@ def view_markup_sandbox(pctx): preview_text = markup_to_html( pctx.course, pctx.repo, pctx.course_commit_sha, form.cleaned_data["content"]) - except: + except Exception: import sys tp, e, _ = sys.exc_info() @@ -258,7 +258,7 @@ def view_page_sandbox(pctx): page_warnings = vctx.warnings - except: + except Exception: import sys tp, e, _ = sys.exc_info() @@ -304,7 +304,7 @@ def view_page_sandbox(pctx): try: page = instantiate_flow_page("sandbox", pctx.repo, page_desc, pctx.course_commit_sha) - except: + except Exception: import sys tp, e, _ = sys.exc_info() @@ -378,7 +378,7 @@ def view_page_sandbox(pctx): page_form = page.make_form(page_context, page_data, answer_data, page_behavior) - except: + except Exception: import sys tp, e, _ = sys.exc_info() diff --git a/course/templatetags/coursetags.py b/course/templatetags/coursetags.py index 0bcd1df26fc81cf90bbd900830b4a169647a8798..6d15e4a2ed3cefbfa7065937609e00ae1f22ff01 100644 --- a/course/templatetags/coursetags.py +++ b/course/templatetags/coursetags.py @@ -86,7 +86,7 @@ def has_permission(participation, arg): if len(arg_list) > 1: argument = arg_list[1] has_pperm = participation.has_permission(perm, argument) - except: + except Exception: # fail silently pass diff --git a/course/validation.py b/course/validation.py index 76c1739a77473ff8410476b405d432425e7a2090..64d56c97807e40af6e75bd5587712a6d6dae2eac 100644 --- a/course/validation.py +++ b/course/validation.py @@ -280,7 +280,7 @@ def validate_markup(vctx, location, markup_str): text=markup_str, reverse_func=reverse_func, validate_only=True) - except: + except Exception: from traceback import print_exc print_exc() @@ -479,7 +479,7 @@ def validate_flow_page(vctx, location, page_desc): class_(vctx, location, page_desc) except ValidationError: raise - except: + except Exception: tp, e, __ = sys.exc_info() from traceback import format_exc @@ -1171,7 +1171,7 @@ def get_yaml_from_repo_safely(repo, full_name, commit_sha): return get_yaml_from_repo( repo=repo, full_name=full_name, commit_sha=commit_sha, cached=False) - except: + except Exception: from traceback import print_exc print_exc() diff --git a/course/versioning.py b/course/versioning.py index aa024406614ad8f5f8dffc38840cdca97103670a..a86604e914d6c79bb03c8defe57f81562537f5c4 100644 --- a/course/versioning.py +++ b/course/versioning.py @@ -278,7 +278,7 @@ def set_up_new_course(request): messages.add_message(request, messages.INFO, _("Course content validated, creation " "succeeded.")) - except: + except Exception: # Don't coalesce this handler with the one below. We only want # to delete the directory if we created it. Trust me. diff --git a/tests/base_test_mixins.py b/tests/base_test_mixins.py index 129b7a68431b2b29ca78604ec1849b121ec1d468..0aeac77ae02383b406bff5acc7f9ea657b609edd 100644 --- a/tests/base_test_mixins.py +++ b/tests/base_test_mixins.py @@ -250,7 +250,7 @@ class CoursesTestMixinBase(SuperuserCreateMixin): try: # TODO: why pop failed here? password = create_user_kwargs["password"] - except: + except Exception: raise user.set_password(password) user.save() diff --git a/tests/test_checks.py b/tests/test_checks.py index f133df06d2c8b5c41a5ec3ea7e4522a4818bba37..430f11c1e18e8ee5b1e3ee3e953b3b874cbdfe71 100644 --- a/tests/test_checks.py +++ b/tests/test_checks.py @@ -27,7 +27,7 @@ from django.test import SimpleTestCase from django.test.utils import override_settings try: from unittest import mock -except: +except Exception: import mock diff --git a/tests/utils.py b/tests/utils.py index 0a098dbc146f5ff3eae569428aded50b72f92dae..e1a1924a85c1842aca77687e4479ac817bd51386 100644 --- a/tests/utils.py +++ b/tests/utils.py @@ -6,7 +6,7 @@ from django.core import mail try: from unittest import mock # noqa -except: +except Exception: import mock # noqa