refactor: pyupgrade second iteration (#27460)
This commit is contained in:
@@ -249,6 +249,6 @@ def page_title_breadcrumbs(*crumbs, **kwargs):
|
||||
separator = kwargs.get("separator", " | ")
|
||||
crumbs = [c for c in crumbs if c is not None]
|
||||
if crumbs:
|
||||
return '{}{}{}'.format(separator.join(crumbs), separator, platform_name)
|
||||
return f'{separator.join(crumbs)}{separator}{platform_name}'
|
||||
else:
|
||||
return platform_name
|
||||
|
||||
@@ -163,7 +163,7 @@ def update_account_settings(requesting_user, update, username=None):
|
||||
raise err
|
||||
except Exception as err:
|
||||
raise AccountUpdateError( # lint-amnesty, pylint: disable=raise-missing-from
|
||||
"Error thrown when saving account updates: '{}'".format(str(err))
|
||||
f"Error thrown when saving account updates: '{str(err)}'"
|
||||
)
|
||||
|
||||
_send_email_change_requests_if_needed(update, user)
|
||||
@@ -200,7 +200,7 @@ def _validate_email_change(user, data, field_errors):
|
||||
student_views.validate_new_email(user, new_email)
|
||||
except ValueError as err:
|
||||
field_errors["email"] = {
|
||||
"developer_message": "Error thrown from validate_new_email: '{}'".format(str(err)),
|
||||
"developer_message": f"Error thrown from validate_new_email: '{str(err)}'",
|
||||
"user_message": str(err)
|
||||
}
|
||||
return
|
||||
@@ -222,7 +222,7 @@ def _validate_secondary_email(user, data, field_errors):
|
||||
student_views.validate_secondary_email(user, secondary_email)
|
||||
except ValueError as err:
|
||||
field_errors["secondary_email"] = {
|
||||
"developer_message": "Error thrown from validate_secondary_email: '{}'".format(str(err)),
|
||||
"developer_message": f"Error thrown from validate_secondary_email: '{str(err)}'",
|
||||
"user_message": str(err)
|
||||
}
|
||||
else:
|
||||
@@ -321,7 +321,7 @@ def _send_email_change_requests_if_needed(data, user):
|
||||
student_views.do_email_change_request(user, new_email)
|
||||
except ValueError as err:
|
||||
raise AccountUpdateError( # lint-amnesty, pylint: disable=raise-missing-from
|
||||
"Error thrown from do_email_change_request: '{}'".format(str(err)),
|
||||
f"Error thrown from do_email_change_request: '{str(err)}'",
|
||||
user_message=str(err)
|
||||
)
|
||||
|
||||
@@ -335,7 +335,7 @@ def _send_email_change_requests_if_needed(data, user):
|
||||
)
|
||||
except ValueError as err:
|
||||
raise AccountUpdateError( # lint-amnesty, pylint: disable=raise-missing-from
|
||||
"Error thrown from do_email_change_request: '{}'".format(str(err)),
|
||||
f"Error thrown from do_email_change_request: '{str(err)}'",
|
||||
user_message=str(err)
|
||||
)
|
||||
|
||||
|
||||
@@ -407,7 +407,7 @@ class AccountLegacyProfileSerializer(serializers.HyperlinkedModelSerializer, Rea
|
||||
# If we have encountered any validation errors, return them to the user.
|
||||
raise errors.AccountValidationError({
|
||||
'social_links': {
|
||||
"developer_message": "Error when adding new social link: '{}'".format(str(err)),
|
||||
"developer_message": f"Error when adding new social link: '{str(err)}'",
|
||||
"user_message": str(err)
|
||||
}
|
||||
})
|
||||
|
||||
@@ -802,7 +802,7 @@ class AccountRetirementStatusView(ViewSet):
|
||||
except ValueError:
|
||||
return Response('Invalid cool_off_days, should be integer.', status=status.HTTP_400_BAD_REQUEST)
|
||||
except KeyError as exc:
|
||||
return Response('Missing required parameter: {}'.format(str(exc)),
|
||||
return Response(f'Missing required parameter: {str(exc)}',
|
||||
status=status.HTTP_400_BAD_REQUEST)
|
||||
except RetirementStateError as exc:
|
||||
return Response(str(exc), status=status.HTTP_400_BAD_REQUEST)
|
||||
@@ -842,9 +842,9 @@ class AccountRetirementStatusView(ViewSet):
|
||||
return Response(serializer.data)
|
||||
# This should only occur on the datetime conversion of the start / end dates.
|
||||
except ValueError as exc:
|
||||
return Response('Invalid start or end date: {}'.format(str(exc)), status=status.HTTP_400_BAD_REQUEST)
|
||||
return Response(f'Invalid start or end date: {str(exc)}', status=status.HTTP_400_BAD_REQUEST)
|
||||
except KeyError as exc:
|
||||
return Response('Missing required parameter: {}'.format(str(exc)),
|
||||
return Response(f'Missing required parameter: {str(exc)}',
|
||||
status=status.HTTP_400_BAD_REQUEST)
|
||||
except RetirementState.DoesNotExist:
|
||||
return Response('Unknown retirement state.', status=status.HTTP_400_BAD_REQUEST)
|
||||
|
||||
@@ -89,7 +89,7 @@ class Command(BaseCommand):
|
||||
|
||||
updated_count += curr
|
||||
|
||||
print('Updated rows {} to {}, {} rows affected'.format(start, end - 1, curr))
|
||||
print(f'Updated rows {start} to {end - 1}, {curr} rows affected')
|
||||
|
||||
if end >= max_id:
|
||||
break
|
||||
|
||||
@@ -77,7 +77,7 @@ class Command(BaseCommand):
|
||||
user for user in users
|
||||
if UserAttribute.get_user_attribute(user, 'created_on_site') == site_domain
|
||||
]
|
||||
self.stdout.write('\tSite Users={count}'.format(count=len(site_users)))
|
||||
self.stdout.write(f'\tSite Users={len(site_users)}')
|
||||
|
||||
return site_users
|
||||
|
||||
@@ -217,7 +217,7 @@ class Command(BaseCommand):
|
||||
try:
|
||||
self.stdout.write(f'Command execution started with options = {options}.')
|
||||
hubspot_sites = self._get_hubspot_enabled_sites()
|
||||
self.stdout.write('{count} hubspot enabled sites found.'.format(count=len(hubspot_sites)))
|
||||
self.stdout.write(f'{len(hubspot_sites)} hubspot enabled sites found.')
|
||||
users_queryset = self._get_users_queryset(initial_sync_days)
|
||||
users_count = users_queryset.count()
|
||||
self.stdout.write(f'Users count={users_count}')
|
||||
|
||||
@@ -299,7 +299,7 @@ def update_email_opt_in(user, org, opt_in):
|
||||
_track_update_email_opt_in(user.id, org, opt_in)
|
||||
except IntegrityError as err:
|
||||
log.warning(
|
||||
"Could not update organization wide preference due to IntegrityError: {}".format(str(err))
|
||||
f"Could not update organization wide preference due to IntegrityError: {str(err)}"
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -68,7 +68,7 @@ class TestRedirectUtils(TestCase):
|
||||
'client_id': application.client_id,
|
||||
'redirect_url': redirect_url,
|
||||
}
|
||||
req = self.request.get('/logout?{}'.format(urlencode(params)), HTTP_HOST=host)
|
||||
req = self.request.get(f'/logout?{urlencode(params)}', HTTP_HOST=host)
|
||||
actual_is_safe = self._is_safe_redirect(req, redirect_url)
|
||||
assert actual_is_safe == expected_is_safe
|
||||
|
||||
|
||||
@@ -210,7 +210,7 @@ class AutoAuthEnabledTestCase(AutoAuthTestCase, ModuleStoreTestCase):
|
||||
if settings.ROOT_URLCONF == 'lms.urls':
|
||||
url_pattern = '/course/'
|
||||
else:
|
||||
url_pattern = '/course/{}'.format(str(course_key))
|
||||
url_pattern = f'/course/{str(course_key)}'
|
||||
|
||||
assert response.url.endswith(url_pattern)
|
||||
|
||||
|
||||
@@ -217,7 +217,7 @@ class LoginAndRegistrationTest(ThirdPartyAuthTestMixin, UrlResetMixin, ModuleSto
|
||||
with with_comprehensive_theme_context(theme):
|
||||
response = self.client.get(reverse(url_name), params, HTTP_ACCEPT="text/html")
|
||||
|
||||
expected_url = '/login?{}'.format(self._finish_auth_url_param(params))
|
||||
expected_url = f'/login?{self._finish_auth_url_param(params)}'
|
||||
self.assertNotContains(response, expected_url)
|
||||
|
||||
@mock.patch.dict(settings.FEATURES, {"ENABLE_THIRD_PARTY_AUTH": False})
|
||||
@@ -655,7 +655,7 @@ class LoginAndRegistrationTest(ThirdPartyAuthTestMixin, UrlResetMixin, ModuleSto
|
||||
'/account/finish_auth?next=%2Fdashboard'
|
||||
"""
|
||||
return urlencode({
|
||||
'next': '/account/finish_auth?{}'.format(urlencode(params))
|
||||
'next': f'/account/finish_auth?{urlencode(params)}'
|
||||
})
|
||||
|
||||
def test_english_by_default(self):
|
||||
|
||||
@@ -111,7 +111,7 @@ class VerifiedTrackCohortedCourse(models.Model):
|
||||
CACHE_NAMESPACE = "verified_track_content.VerifiedTrackCohortedCourse.cache."
|
||||
|
||||
def __str__(self):
|
||||
return "Course: {}, enabled: {}".format(str(self.course_key), self.enabled)
|
||||
return f"Course: {str(self.course_key)}, enabled: {self.enabled}"
|
||||
|
||||
@classmethod
|
||||
def verified_cohort_name_for_course(cls, course_key):
|
||||
|
||||
@@ -59,7 +59,7 @@ class CourseWaffleFlag(LegacyWaffleFlag):
|
||||
# Import is placed here to avoid model import at project startup.
|
||||
from .models import WaffleFlagCourseOverrideModel
|
||||
|
||||
cache_key = "{}.{}".format(self.name, str(course_key))
|
||||
cache_key = f"{self.name}.{str(course_key)}"
|
||||
course_override = self.cached_flags().get(cache_key)
|
||||
|
||||
if course_override is None:
|
||||
|
||||
@@ -62,4 +62,4 @@ class WaffleFlagCourseOverrideModel(ConfigurationModel):
|
||||
|
||||
def __str__(self):
|
||||
enabled_label = "Enabled" if self.enabled else "Not Enabled"
|
||||
return "Course '{}': Persistent Grades {}".format(str(self.course_id), enabled_label)
|
||||
return f"Course '{str(self.course_id)}': Persistent Grades {enabled_label}"
|
||||
|
||||
@@ -40,7 +40,7 @@ class EphemeralKeyValueStore(KeyValueStore):
|
||||
"""
|
||||
Expand the given XBlock key tuple to a format we can use as a key.
|
||||
"""
|
||||
return "ephemeral-xblock:{}".format(repr(tuple(key)))
|
||||
return f"ephemeral-xblock:{repr(tuple(key))}"
|
||||
|
||||
@property
|
||||
def _cache(self):
|
||||
|
||||
Reference in New Issue
Block a user