Skip to content

Commit

Permalink
fix: fix quality warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
UsamaSadiq committed Jan 30, 2025
1 parent 6a9d802 commit fc2fa81
Show file tree
Hide file tree
Showing 10 changed files with 33 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,15 @@ def handle(self, *args, **options):
tarball = tasks.create_export_tarball(library, library_key, {}, None)
except Exception as e:
raise CommandError(f'Failed to export "{library_key}" with "{e}"') # lint-amnesty, pylint: disable=raise-missing-from
else:
with tarball:
# Save generated archive with keyed filename
prefix, suffix, n = str(library_key).replace(':', '+'), '.tar.gz', 0
while os.path.exists(prefix + suffix):
n += 1
prefix = '{}_{}'.format(prefix.rsplit('_', 1)[0], n) if n > 1 else f'{prefix}_1'
filename = prefix + suffix
target = os.path.join(dest_path, filename)
tarball.file.seek(0)
with open(target, 'wb') as f:
shutil.copyfileobj(tarball.file, f)
print(f'Library "{library.location.library_key}" exported to "{target}"')
with tarball:
# Save generated archive with keyed filename
prefix, suffix, n = str(library_key).replace(':', '+'), '.tar.gz', 0
while os.path.exists(prefix + suffix):
n += 1
prefix = '{}_{}'.format(prefix.rsplit('_', 1)[0], n) if n > 1 else f'{prefix}_1'
filename = prefix + suffix
target = os.path.join(dest_path, filename)
tarball.file.seek(0)
with open(target, 'wb') as f:
shutil.copyfileobj(tarball.file, f)
print(f'Library "{library.location.library_key}" exported to "{target}"')
5 changes: 2 additions & 3 deletions common/djangoapps/track/views/segmentio.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,9 +205,8 @@ def track_segmentio_event(request): # pylint: disable=too-many-statements
raise EventValidationError(ERROR_USER_NOT_EXIST) # lint-amnesty, pylint: disable=raise-missing-from
except ValueError:
raise EventValidationError(ERROR_INVALID_USER_ID) # lint-amnesty, pylint: disable=raise-missing-from
else:
context['user_id'] = user.id
context['username'] = user.username
context['user_id'] = user.id
context['username'] = user.username

# course_id is expected to be provided in the context when applicable
course_id = context.get('course_id')
Expand Down
3 changes: 1 addition & 2 deletions lms/djangoapps/static_template_view/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,8 +92,7 @@ def render_press_release(request, slug):
resp = render_to_response('static_templates/press_releases/' + template, {})
except TemplateDoesNotExist:
raise Http404 # lint-amnesty, pylint: disable=raise-missing-from
else:
return resp
return resp


@fix_crum_request
Expand Down
3 changes: 1 addition & 2 deletions openedx/core/djangoapps/credit/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ def update_credit_course_requirements(course_id):
except (InvalidKeyError, ItemNotFoundError, InvalidCreditRequirements) as exc:
LOGGER.error('Error on adding the requirements for course %s - %s', course_id, str(exc))
raise update_credit_course_requirements.retry(args=[course_id], exc=exc)
else:
LOGGER.info('Requirements added for course %s', course_id)
LOGGER.info('Requirements added for course %s', course_id)


def _get_course_credit_requirements(course_key):
Expand Down
3 changes: 1 addition & 2 deletions openedx/core/djangoapps/enrollments/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -341,8 +341,7 @@ def get_course_enrollment_info(course_id, include_expired=False):
msg = f"Requested enrollment information for unknown course {course_id}"
log.warning(msg)
raise CourseNotFoundError(msg) # lint-amnesty, pylint: disable=raise-missing-from
else:
return CourseSerializer(course, include_expired=include_expired).data
return CourseSerializer(course, include_expired=include_expired).data


def get_user_roles(username):
Expand Down
15 changes: 7 additions & 8 deletions openedx/core/djangoapps/safe_sessions/middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,14 +244,13 @@ def parse(cls, safe_cookie_string):
raise SafeCookieError( # lint-amnesty, pylint: disable=raise-missing-from
f"SafeCookieData BWC parse error: {safe_cookie_string!r}."
)
else:
if safe_cookie_data.version != cls.CURRENT_VERSION:
raise SafeCookieError(
"SafeCookieData version {!r} is not supported. Current version is {}.".format(
safe_cookie_data.version,
cls.CURRENT_VERSION,
))
return safe_cookie_data
if safe_cookie_data.version != cls.CURRENT_VERSION:
raise SafeCookieError(
"SafeCookieData version {!r} is not supported. Current version is {}.".format(
safe_cookie_data.version,
cls.CURRENT_VERSION,
))
return safe_cookie_data

def __str__(self):
"""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,10 @@ def handle(self, *args, **options):
optout_rows[end_idx][0], optout_rows[end_idx][1],
str(err))
raise
else:
cursor.execute('COMMIT;')
log.info("Committed opt-out for rows (%s, %s) through (%s, %s).",
optout_rows[start_idx][0], optout_rows[start_idx][1],
optout_rows[end_idx][0], optout_rows[end_idx][1])
cursor.execute('COMMIT;')
log.info("Committed opt-out for rows (%s, %s) through (%s, %s).",
optout_rows[start_idx][0], optout_rows[start_idx][1],
optout_rows[end_idx][0], optout_rows[end_idx][1])
log.info("Sleeping %s seconds...", sleep_between)
time.sleep(sleep_between)
curr_row_idx += chunk_size
5 changes: 2 additions & 3 deletions openedx/core/lib/celery/task_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,8 @@ def emulate_http_request(site=None, user=None, middleware_classes=None):
for middleware in reversed(middleware_instances):
_run_method_if_implemented(middleware, 'process_exception', request, exc)
raise
else:
for middleware in reversed(middleware_instances):
_run_method_if_implemented(middleware, 'process_response', request, response)
for middleware in reversed(middleware_instances):
_run_method_if_implemented(middleware, 'process_response', request, response)


def _run_method_if_implemented(instance, method_name, *args, **kwargs):
Expand Down
3 changes: 1 addition & 2 deletions xmodule/capa/tests/test_input_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ def render_to_xml(self, context_dict):
except Exception as exc:
raise TemplateError("Could not parse XML from '{0}': {1}".format( # lint-amnesty, pylint: disable=raise-missing-from
xml_str, str(exc)))
else:
return xml
return xml

def assert_has_xpath(self, xml_root, xpath, context_dict, exact_num=1):
"""
Expand Down
5 changes: 2 additions & 3 deletions xmodule/split_test_block.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,9 +419,8 @@ def log_child_render(self, request, suffix=''): # lint-amnesty, pylint: disable
)
)
raise
else:
self.runtime.publish(self, 'xblock.split_test.child_render', {'child_id': child_id})
return Response()
self.runtime.publish(self, 'xblock.split_test.child_render', {'child_id': child_id})
return Response()

def get_icon_class(self):
return self.child.get_icon_class() if self.child else 'other'
Expand Down

0 comments on commit fc2fa81

Please sign in to comment.