refactor: pyupgrade second iteration (#27447)

This commit is contained in:
Usama Sadiq
2021-05-10 13:43:38 +05:00
committed by GitHub
parent 5625d5e77b
commit 1b55cc2957
12 changed files with 14 additions and 14 deletions

View File

@@ -4,6 +4,7 @@ Unit tests for integration of the django-user-tasks app and its REST API.
import json
import logging
from unittest import mock
from unittest.mock import patch
from uuid import uuid4
import ddt
@@ -14,7 +15,6 @@ from django.core import mail
from django.test import override_settings
from django.urls import reverse
from edx_toggles.toggles.testutils import override_waffle_flag
from mock import patch
from rest_framework.test import APITestCase
from user_tasks.models import UserTaskArtifact, UserTaskStatus
from user_tasks.serializers import ArtifactSerializer, StatusSerializer

View File

@@ -154,7 +154,7 @@ class Command(BaseCommand):
max(len(str(result[col])) for result in results + [headers])
for col in range(len(results[0]))
]
id_format = "{{:>{}}} |".format(len(str(len(results))))
id_format = f"{{:>{len(str(len(results)))}}} |"
col_format = "| {{:>{}}} |"
self.stdout.write(id_format.format(""), ending='')

View File

@@ -22,7 +22,7 @@ class Command(BaseCommand):
"""
# can this query modulestore for the list of write accessible stores or does that violate command pattern?
help = "Create a course in one of {}".format([ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split])
help = f"Create a course in one of {[ModuleStoreEnum.Type.mongo, ModuleStoreEnum.Type.split]}"
def add_arguments(self, parser):
parser.add_argument('modulestore',
@@ -86,6 +86,6 @@ class Command(BaseCommand):
run,
fields
)
self.stdout.write("Created {}".format(str(new_course.id)))
self.stdout.write(f"Created {str(new_course.id)}")
except DuplicateCourseError:
self.stdout.write("Course already exists")

View File

@@ -27,5 +27,5 @@ class Command(BaseCommand):
else:
course_ids = [course.id for course in modulestore().get_courses()]
if query_yes_no("Emptying {} trashcan(s). Confirm?".format(len(course_ids)), default="no"):
if query_yes_no(f"Emptying {len(course_ids)} trashcan(s). Confirm?", default="no"):
empty_asset_trashcan(course_ids)

View File

@@ -27,8 +27,8 @@ class Command(BaseCommand):
print("=" * 80)
print("=" * 30 + "> Export summary")
print("Total number of courses to export: {}".format(len(courses)))
print("Total number of courses which failed to export: {}".format(len(failed_export_courses)))
print(f"Total number of courses to export: {len(courses)}")
print(f"Total number of courses which failed to export: {len(failed_export_courses)}")
print("List of export failed courses ids:")
print("\n".join(failed_export_courses))
print("=" * 80)

View File

@@ -59,7 +59,7 @@ class Command(BaseCommand):
# Create the course
try:
new_course = create_new_course_in_store("split", user, org, num, run, fields)
logger.info("Created {}".format(str(new_course.id)))
logger.info(f"Created {str(new_course.id)}")
except DuplicateCourseError:
logger.warning("Course already exists for %s, %s, %s", org, num, run)

View File

@@ -51,7 +51,7 @@ class Command(BaseCommand):
try:
safetar_extractall(tar_file, course_dir.encode('utf-8'))
except SuspiciousOperation as exc:
raise CommandError('\n=== Course import {}: Unsafe tar file - {}\n'.format(archive_path, exc.args[0])) # lint-amnesty, pylint: disable=raise-missing-from
raise CommandError(f'\n=== Course import {archive_path}: Unsafe tar file - {exc.args[0]}\n') # lint-amnesty, pylint: disable=raise-missing-from
finally:
tar_file.close()

View File

@@ -59,7 +59,7 @@ class Command(BaseCommand):
course_key.run,
fields,
)
logger.info("Created {}".format(str(new_course.id)))
logger.info(f"Created {str(new_course.id)}")
except DuplicateCourseError:
logger.warning(
"Course already exists for %s, %s, %s. Skipping",

View File

@@ -674,7 +674,7 @@ def course_index(request, course_key):
reindex_link = None
if settings.FEATURES.get('ENABLE_COURSEWARE_INDEX', False):
if GlobalStaff().has_user(request.user):
reindex_link = "/course/{course_id}/search_reindex".format(course_id=str(course_key))
reindex_link = f"/course/{str(course_key)}/search_reindex"
sections = course_module.get_children()
course_structure = _course_outline_json(request, course_module)
locator_to_show = request.GET.get('show', None)

View File

@@ -247,7 +247,7 @@ def add_entrance_exam_milestone(course_id, x_block): # lint-amnesty, pylint: di
if len(milestones): # lint-amnesty, pylint: disable=len-as-condition
milestone = milestones[0]
else:
description = 'Autogenerated during {} entrance exam creation.'.format(str(course_id))
description = f'Autogenerated during {str(course_id)} entrance exam creation.'
milestone = milestones_helpers.add_milestone({
'name': _('Completed Course Entrance Exam'),
'namespace': milestone_namespace,

View File

@@ -28,4 +28,4 @@ def export_course_metadata_task(self, course_key_string): # pylint: disable=unu
course_key = CourseKey.from_string(course_key_string)
highlights = get_all_course_highlights(course_key)
highlights_content = ContentFile(json.dumps({'highlights': highlights}))
course_metadata_export_storage.save('course_metadata_export/{}.json'.format(course_key), highlights_content)
course_metadata_export_storage.save(f'course_metadata_export/{course_key}.json', highlights_content)

View File

@@ -52,5 +52,5 @@ class TestExportCourseMetadata(SharedModuleStoreTestCase):
'{"highlights": [["week1highlight1", "week1highlight2"], ["week1highlight1", "week1highlight2"], [], []]}'
)
patched_storage.save.assert_called_once_with(
'course_metadata_export/{}.json'.format(self.course_key), patched_content.return_value
f'course_metadata_export/{self.course_key}.json', patched_content.return_value
)