diff --git a/cms/djangoapps/contentstore/video_storage_handlers.py b/cms/djangoapps/contentstore/video_storage_handlers.py index 4cc5c738b5dc..1433bf2fc3ac 100644 --- a/cms/djangoapps/contentstore/video_storage_handlers.py +++ b/cms/djangoapps/contentstore/video_storage_handlers.py @@ -995,9 +995,9 @@ def get_course_youtube_edx_video_ids(course_id): f"InvalidKeyError occurred while getting YouTube video IDs for course_id: {course_id}: {error}" ) return JsonResponse({'error': invalid_key_error_msg}, status=500) - except Exception as error: + except (TypeError, AttributeError) as error: LOGGER.exception( - f"Unexpected error occurred while getting YouTube video IDs for course_id: {course_id}: {error}" + f"Error occurred while getting YouTube video IDs for course_id: {course_id}: {error}" ) return JsonResponse({'error': unexpected_error_msg}, status=500) diff --git a/common/djangoapps/student/models/user.py b/common/djangoapps/student/models/user.py index 9d979beb19cb..7fe69bd678e4 100644 --- a/common/djangoapps/student/models/user.py +++ b/common/djangoapps/student/models/user.py @@ -1028,7 +1028,7 @@ def clear_lockout_counter(cls, user): entry = cls._get_record_for_user(user) entry.delete() except ObjectDoesNotExist: - return + pass def __str__(self): """Str -> Username: count - date.""" diff --git a/common/djangoapps/student/tests/test_parental_controls.py b/common/djangoapps/student/tests/test_parental_controls.py index 4e49f88af992..62cd30707d5a 100644 --- a/common/djangoapps/student/tests/test_parental_controls.py +++ b/common/djangoapps/student/tests/test_parental_controls.py @@ -59,7 +59,7 @@ def test_child_user(self): self.set_year_of_birth(current_year - 13) assert self.profile.requires_parental_consent() assert self.profile.requires_parental_consent(year=current_year) - assert not self.profile.requires_parental_consent(year=(current_year + 1)) + assert not self.profile.requires_parental_consent(year=current_year + 1) # Verify for a child born 14 years ago self.set_year_of_birth(current_year - 14) diff --git a/common/djangoapps/student/tests/test_views.py b/common/djangoapps/student/tests/test_views.py index 16bab13b90e7..15ecdab23642 100644 --- a/common/djangoapps/student/tests/test_views.py +++ b/common/djangoapps/student/tests/test_views.py @@ -51,8 +51,8 @@ TOMORROW = now() + timedelta(days=1) ONE_WEEK_AGO = now() - timedelta(weeks=1) -THREE_YEARS_FROM_NOW = now() + timedelta(days=(365 * 3)) -THREE_YEARS_AGO = now() - timedelta(days=(365 * 3)) +THREE_YEARS_FROM_NOW = now() + timedelta(days=365 * 3) +THREE_YEARS_AGO = now() - timedelta(days=365 * 3) # Name of the method to mock for Content Type Gating. GATING_METHOD_NAME = 'openedx.features.content_type_gating.models.ContentTypeGatingConfig.enabled_for_enrollment' diff --git a/common/djangoapps/third_party_auth/api/tests/test_views.py b/common/djangoapps/third_party_auth/api/tests/test_views.py index aea4c18367e6..948314a0672f 100644 --- a/common/djangoapps/third_party_auth/api/tests/test_views.py +++ b/common/djangoapps/third_party_auth/api/tests/test_views.py @@ -60,7 +60,7 @@ def setUp(self): # pylint: disable=arguments-differ # Create several users and link each user to Google and TestShib for username in LINKED_USERS: - make_superuser = (username == ADMIN_USERNAME) + make_superuser = username == ADMIN_USERNAME make_staff = (username == STAFF_USERNAME) or make_superuser user = UserFactory.create( username=username, diff --git a/common/djangoapps/third_party_auth/lti.py b/common/djangoapps/third_party_auth/lti.py index 3895c888661c..496b7dcbbbab 100644 --- a/common/djangoapps/third_party_auth/lti.py +++ b/common/djangoapps/third_party_auth/lti.py @@ -177,7 +177,7 @@ def safe_int(value): # As this must take constant time, do not use shortcutting operators such as 'and'. # Instead, use constant time operators such as '&', which is the bitwise and. - valid = (lti_consumer_valid) + valid = lti_consumer_valid valid = valid & (submitted_signature == computed_signature) valid = valid & (request.oauth_version == '1.0') valid = valid & (request.oauth_signature_method == 'HMAC-SHA1') diff --git a/lms/djangoapps/bulk_email/models.py b/lms/djangoapps/bulk_email/models.py index d4f238fd9453..b1a7aa574408 100644 --- a/lms/djangoapps/bulk_email/models.py +++ b/lms/djangoapps/bulk_email/models.py @@ -114,7 +114,7 @@ def get_users(self, course_id, user_id=None): """ staff_qset = CourseStaffRole(course_id).users_with_role() instructor_qset = CourseInstructorRole(course_id).users_with_role() - staff_instructor_qset = (staff_qset | instructor_qset) + staff_instructor_qset = staff_qset | instructor_qset enrollment_query = models.Q( is_active=True, courseenrollment__course_id=course_id, diff --git a/lms/djangoapps/course_blocks/transformers/tests/test_visibility.py b/lms/djangoapps/course_blocks/transformers/tests/test_visibility.py index 8ceb821a642a..6b1f311ba44c 100644 --- a/lms/djangoapps/course_blocks/transformers/tests/test_visibility.py +++ b/lms/djangoapps/course_blocks/transformers/tests/test_visibility.py @@ -36,7 +36,7 @@ def test_block_visibility( ): for idx, _ in enumerate(self.parents_map): block = self.get_block(idx) - block.visible_to_staff_only = (idx in staff_only_blocks) + block.visible_to_staff_only = idx in staff_only_blocks update_block(block) self.assert_transform_results( diff --git a/lms/djangoapps/course_goals/management/commands/goal_reminder_email.py b/lms/djangoapps/course_goals/management/commands/goal_reminder_email.py index a9ab150221ea..944a18feff2e 100644 --- a/lms/djangoapps/course_goals/management/commands/goal_reminder_email.py +++ b/lms/djangoapps/course_goals/management/commands/goal_reminder_email.py @@ -224,8 +224,11 @@ def _handle_all_goals(self): 'goal_count': total_goals, } ) - log.info(f'Processing course goals, total goal count {total_goals},' - + f'timestamp: {datetime.now()}, uuid: {session_id}') + log.info('Processing course goals, total goal count {}, timestamp: {}, uuid: {}'.format( + total_goals, + datetime.now(), + session_id + )) for goal in course_goals: # emulate a request for waffle's benefit with emulate_http_request(site=Site.objects.get_current(), user=goal.user): @@ -234,8 +237,13 @@ def _handle_all_goals(self): else: filtered_count += 1 if (sent_count + filtered_count) % 10000 == 0: - log.info(f'Processing course goals: sent {sent_count} filtered {filtered_count} out of {total_goals},' - + f'timestamp: {datetime.now()}, uuid: {session_id}') + log.info('Processing course goals: sent {} filtered {} out of {}, timestamp: {}, uuid: {}'.format( + sent_count, + filtered_count, + total_goals, + datetime.now(), + session_id + )) tracker.emit( 'edx.course.goal.email.session_completed', @@ -247,8 +255,10 @@ def _handle_all_goals(self): 'emails_filtered': filtered_count, } ) - log.info(f'Processing course goals complete: sent {sent_count} emails, filtered out {filtered_count} emails' - + f'timestamp: {datetime.now()}, uuid: {session_id}') + log.info('Processing course goals complete: sent {} emails, ' + 'filtered out {} emails, timestamp: {}, ' + 'uuid: {}'.format(sent_count, filtered_count, datetime.now(), session_id) + ) @staticmethod def handle_goal(goal, today, sunday_date, monday_date, session_id): @@ -346,5 +356,5 @@ def send_email_using_ses(user, msg): log.info(f"Goal Reminder Email: email sent using SES with message ID {response['MessageId']}") send_ace_message_sent_signal(DjangoEmailChannel, msg) - except Exception as e: + except Exception as e: # pylint: disable=broad-exception-caught log.error(f"Goal Reminder Email: Error sending email using SES: {e}") diff --git a/lms/djangoapps/courseware/tests/test_date_summary.py b/lms/djangoapps/courseware/tests/test_date_summary.py index e487af8a1f70..1762d37bdee0 100644 --- a/lms/djangoapps/courseware/tests/test_date_summary.py +++ b/lms/djangoapps/courseware/tests/test_date_summary.py @@ -617,7 +617,7 @@ def test_verification_deadline_date_denied(self): block = VerificationDeadlineDate(course, user) assert block.css_class == 'verification-deadline-passed' assert block.title == 'Missed Verification Deadline' - assert block.date == (datetime.now(utc) + timedelta(days=(- 1))) + assert block.date == (datetime.now(utc) + timedelta(days=- 1)) assert block.description == "Unfortunately you missed this course's deadline for a successful verification." assert block.link_text == 'Learn More' assert block.link == '' diff --git a/lms/djangoapps/discussion/tasks.py b/lms/djangoapps/discussion/tasks.py index 3fef4f5f7cef..d483388f54ae 100644 --- a/lms/djangoapps/discussion/tasks.py +++ b/lms/djangoapps/discussion/tasks.py @@ -120,8 +120,6 @@ def send_ace_message(context): # lint-amnesty, pylint: disable=missing-function log.info('Sending forum comment notification with context %s', message_context) ace.send(message, limit_to_channels=[ChannelType.PUSH]) _track_notification_sent(message, context) - else: - return @shared_task(base=LoggedTask) diff --git a/openedx/core/djangoapps/credit/models.py b/openedx/core/djangoapps/credit/models.py index 2a9fa2088551..9c14a15104b9 100644 --- a/openedx/core/djangoapps/credit/models.py +++ b/openedx/core/djangoapps/credit/models.py @@ -514,7 +514,6 @@ def remove_requirement_status(cls, username, requirement): ) ) log.error(log_msg) - return @classmethod def retire_user(cls, retirement): diff --git a/openedx/core/djangoapps/notifications/views.py b/openedx/core/djangoapps/notifications/views.py index 8e41b11554c8..faf2a4564f76 100644 --- a/openedx/core/djangoapps/notifications/views.py +++ b/openedx/core/djangoapps/notifications/views.py @@ -523,7 +523,7 @@ def post(self, request): 'error': f'Invalid path: {app}.notification_types.{notification_type}.{channel}' }) - except Exception as e: + except (KeyError, AttributeError, ValueError) as e: errors.append({ 'course_id': str(preference.course_id), 'error': str(e) @@ -551,7 +551,7 @@ def post(self, request): status=status.HTTP_200_OK if updated_courses else status.HTTP_400_BAD_REQUEST ) - except Exception as e: + except (KeyError, AttributeError, ValueError) as e: return Response({ 'status': 'error', 'message': str(e) diff --git a/pylintrc b/pylintrc index e06941853774..de88463ddb0c 100644 --- a/pylintrc +++ b/pylintrc @@ -317,10 +317,7 @@ disable = too-many-positional-arguments, possibly-used-before-assignment, use-dict-literal, - useless-return, - superfluous-parens, - logging-not-lazy, - broad-exception-caught, + superfluous-parens [REPORTS] output-format = text @@ -417,4 +414,4 @@ int-import-graph = [EXCEPTIONS] overgeneral-exceptions = builtins.Exception -# 85c3d025c367597a0a7b23a05fdde9d8c63e1374 +# 5aea7d7fb264005eb373099c856a54cdfa4f311c diff --git a/pylintrc_tweaks b/pylintrc_tweaks index fb0bebfd2a12..cd8680d4d661 100644 --- a/pylintrc_tweaks +++ b/pylintrc_tweaks @@ -36,10 +36,7 @@ disable+ = too-many-positional-arguments, possibly-used-before-assignment, use-dict-literal, - useless-return, - superfluous-parens, - logging-not-lazy, - broad-exception-caught, + superfluous-parens [BASIC] attr-rgx = [a-z_][a-z0-9_]{2,40}$