Skip to content

Commit

Permalink
fix: enable pylint warnings (#36196)
Browse files Browse the repository at this point in the history
  • Loading branch information
UsamaSadiq authored Feb 3, 2025
1 parent de58fcc commit 1a16073
Show file tree
Hide file tree
Showing 15 changed files with 33 additions and 32 deletions.
4 changes: 2 additions & 2 deletions cms/djangoapps/contentstore/video_storage_handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion common/djangoapps/student/models/user.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand Down
2 changes: 1 addition & 1 deletion common/djangoapps/student/tests/test_parental_controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions common/djangoapps/student/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion common/djangoapps/third_party_auth/api/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion common/djangoapps/third_party_auth/lti.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion lms/djangoapps/bulk_email/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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',
Expand All @@ -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):
Expand Down Expand Up @@ -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}")
2 changes: 1 addition & 1 deletion lms/djangoapps/courseware/tests/test_date_summary.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 == ''
Expand Down
2 changes: 0 additions & 2 deletions lms/djangoapps/discussion/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion openedx/core/djangoapps/credit/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,6 @@ def remove_requirement_status(cls, username, requirement):
)
)
log.error(log_msg)
return

@classmethod
def retire_user(cls, retirement):
Expand Down
4 changes: 2 additions & 2 deletions openedx/core/djangoapps/notifications/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
7 changes: 2 additions & 5 deletions pylintrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -417,4 +414,4 @@ int-import-graph =
[EXCEPTIONS]
overgeneral-exceptions = builtins.Exception

# 85c3d025c367597a0a7b23a05fdde9d8c63e1374
# 5aea7d7fb264005eb373099c856a54cdfa4f311c
5 changes: 1 addition & 4 deletions pylintrc_tweaks
Original file line number Diff line number Diff line change
Expand Up @@ -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}$
Expand Down

0 comments on commit 1a16073

Please sign in to comment.