diff --git a/docs/conf.py b/docs/conf.py index 920755c6..5ee426e6 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -28,13 +28,12 @@ # -- Project information ----------------------------------------------------- -project = 'Django REST Registration' -docs_title = '{project} documentation'.format(project=project) -author = 'Andrzej Pragacz' +project = "Django REST Registration" +docs_title = f"{project} documentation" +author = "Andrzej Pragacz" datetime_now = datetime.datetime.now() current_year = datetime_now -copyright = '{current_year}, {author}'.format( # noqa: E501 pylint: disable=redefined-builtin - author=author, current_year=current_year) +copyright = f"{current_year}, {author}" # pylint: disable=redefined-builtin version = rest_registration.__version__ release = version @@ -213,8 +212,7 @@ } settings_fields_groups_map = settings_fields.SETTINGS_FIELDS_GROUPS_MAP for group_name, settings_fields in settings_fields_groups_map.items(): - ctx_key = 'detailed_configuration__{group_name}'.format( - group_name=group_name) + ctx_key = f"detailed_configuration__{group_name}" jinja_contexts[ctx_key] = { 'settings_fields': settings_fields, 'generate_setting_refs': False, diff --git a/examples/sharedlinks/sharedlinks-backend/links/models.py b/examples/sharedlinks/sharedlinks-backend/links/models.py index e3bda125..b5b532b2 100644 --- a/examples/sharedlinks/sharedlinks-backend/links/models.py +++ b/examples/sharedlinks/sharedlinks-backend/links/models.py @@ -14,7 +14,7 @@ class Link(models.Model): ) def __str__(self): - return '{self.title} ({self.url})'.format(self=self) + return f"{self.title} ({self.url})" def get_num_of_positive_votes(self): return self.votes.filter(positive=True).count() @@ -53,5 +53,4 @@ def __str__(self): else: vote = 'neutral' - return '{vote} vote for {self.link} by {self.voter}'.format( - vote=vote, self=self) + return f"{vote} vote for {self.link} by {self.voter}" diff --git a/examples/sharedlinks/sharedlinks-backend/sharedlinks/settings.py b/examples/sharedlinks/sharedlinks-backend/sharedlinks/settings.py index d3b3b760..e517ac4c 100644 --- a/examples/sharedlinks/sharedlinks-backend/sharedlinks/settings.py +++ b/examples/sharedlinks/sharedlinks-backend/sharedlinks/settings.py @@ -173,7 +173,7 @@ def get_frontend_url(uri): - return 'http://localhost:3000{uri}'.format(uri=uri) + return f"http://localhost:3000{uri}" REST_REGISTRATION = { diff --git a/pyproject.toml b/pyproject.toml index 8ab54e63..41d2b6b7 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -111,7 +111,6 @@ disable = [ "line-too-long", "ungrouped-imports", "fixme", - "consider-using-f-string", ] [tool.pylint.reports] diff --git a/rest_registration/api/views/base.py b/rest_registration/api/views/base.py index 0ec8a147..dc46aac8 100644 --- a/rest_registration/api/views/base.py +++ b/rest_registration/api/views/base.py @@ -27,9 +27,9 @@ def get_serializer_class(self) -> Type[Serializer]: (Eg. admins get full serialization, others get basic serialization) """ assert self.serializer_class is not None, ( - "'%s' should either include a `serializer_class` attribute, " - "or override the `get_serializer_class()` method." - % self.__class__.__name__ + f"'{self.__class__.__name__}' should either include a " + f"`serializer_class` attribute, " + f"or override the `get_serializer_class()` method." ) return self.serializer_class diff --git a/rest_registration/enums.py b/rest_registration/enums.py index a178f79f..4e7481ed 100644 --- a/rest_registration/enums.py +++ b/rest_registration/enums.py @@ -32,7 +32,7 @@ class ErrorCode(_BaseCheckCodeMixin, Enum): INVALID_AUTH_BACKENDS_CONFIG = 14 def get_code_id(self) -> str: - return 'E{self.value:03d}'.format(self=self) + return f"E{self.value:03d}" def get_check_message_class(self) -> Type[CheckMessage]: return checks.Error @@ -46,7 +46,7 @@ class WarningCode(_BaseCheckCodeMixin, Enum): DEPRECATION = 2 def get_code_id(self) -> str: - return 'W{self.value:03d}'.format(self=self) + return f"W{self.value:03d}" def get_check_message_class(self) -> Type[CheckMessage]: return checks.Warning diff --git a/rest_registration/signers/register.py b/rest_registration/signers/register.py index 79ff65af..71acc435 100644 --- a/rest_registration/signers/register.py +++ b/rest_registration/signers/register.py @@ -23,8 +23,7 @@ def _calculate_salt(self, data): # implies changed salt used when verifying the input data. verification_flag_field = get_user_setting('VERIFICATION_FLAG_FIELD') verification_flag = getattr(user, verification_flag_field) - salt = '{self.SALT_BASE}:{verification_flag}'.format( - self=self, verification_flag=verification_flag) + salt = f"{self.SALT_BASE}:{verification_flag}" else: salt = self.SALT_BASE return salt diff --git a/rest_registration/signers/reset_password.py b/rest_registration/signers/reset_password.py index 92562910..09e243df 100644 --- a/rest_registration/signers/reset_password.py +++ b/rest_registration/signers/reset_password.py @@ -22,8 +22,7 @@ def _calculate_salt(self, data): # was caused by previous password reset and the signature # is not valid anymore because changed password hash implies # changed salt used when verifying the input data. - salt = '{self.SALT_BASE}:{user_password_hash}'.format( - self=self, user_password_hash=user_password_hash) + salt = f"{self.SALT_BASE}:{user_password_hash}" else: salt = self.SALT_BASE return salt diff --git a/rest_registration/utils/checks.py b/rest_registration/utils/checks.py index 5d8a6df3..3114f0dc 100644 --- a/rest_registration/utils/checks.py +++ b/rest_registration/utils/checks.py @@ -17,7 +17,7 @@ class CheckCode: def get_full_code_id(self) -> str: app_name = self.get_app_name() code_id = self.get_code_id() - return '{app_name}.{code_id}'.format(app_name=app_name, code_id=code_id) + return f"{app_name}.{code_id}" def get_app_name(self) -> str: raise NotImplementedError() @@ -81,8 +81,7 @@ def check_fun( fun() except Exception as exc: # pylint: disable=broad-except exc_str = str(exc) - msg = '{error_message}: {exc_str}'.format( - error_message=error_message, exc_str=exc_str) + msg = f"{error_message}: {exc_str}" return [ message_cls( msg, diff --git a/rest_registration/utils/email.py b/rest_registration/utils/email.py index e89bce79..8e449f62 100644 --- a/rest_registration/utils/email.py +++ b/rest_registration/utils/email.py @@ -90,8 +90,8 @@ def parse_template_config(template_config_data: Dict[str, Any]) -> EmailTemplate ) else: raise ImproperlyConfigured( - 'Could not parse template config data: {template_config_data}'.format( # noqa: E501 - template_config_data=template_config_data)) + f"Could not parse template config data: {template_config_data}", + ) _validate_template_name_existence(config.subject_template_name) _validate_template_name_existence(config.text_body_template_name) @@ -109,6 +109,6 @@ def _validate_template_name_existence(template_name: str) -> None: get_template(template_name) except TemplateDoesNotExist: raise ImproperlyConfigured( - 'Template {template_name!r} does not exist; ensure that your' - ' Django TEMPLATES setting is configured correctly'.format( - template_name=template_name)) from None + f"Template {template_name!r} does not exist; ensure that your" + f" Django TEMPLATES setting is configured correctly", + ) from None diff --git a/rest_registration/utils/html.py b/rest_registration/utils/html.py index aea66909..44b8a39f 100644 --- a/rest_registration/utils/html.py +++ b/rest_registration/utils/html.py @@ -43,7 +43,7 @@ def handle_endtag(self, tag: str) -> None: last_segment = last_paragraph[-1] if last_paragraph else None if (self._preserve_urls and tag_info.name == 'a' and href and href != last_segment): - self._append_segment('({href})'.format(href=href)) + self._append_segment(f"({href})") if tag == 'p': self._paragraphs.append([]) @@ -58,8 +58,7 @@ def handle_data(self, data: str) -> None: self._append_segment(data) def error(self, message: str) -> None: - raise ValueError("HTML parse error: {message}".format( - message=message)) + raise ValueError(f"HTML parse error: {message}") def get_data(self) -> str: paragraph_texts = [] diff --git a/rest_registration/utils/nested_settings.py b/rest_registration/utils/nested_settings.py index 692450d9..14a3d55c 100644 --- a/rest_registration/utils/nested_settings.py +++ b/rest_registration/utils/nested_settings.py @@ -43,9 +43,7 @@ def is_default(self, attr: str) -> bool: def __getattr__(self, attr: str) -> Any: if attr not in self.defaults.keys(): - raise AttributeError( - "Invalid {self.root_setting_name} setting: '{attr}'".format( - self=self, attr=attr)) + raise AttributeError(f"Invalid {self.root_setting_name} setting: '{attr}'") try: # Check if present in user settings diff --git a/rest_registration/utils/users.py b/rest_registration/utils/users.py index fe7dd7a8..85d9e33e 100644 --- a/rest_registration/utils/users.py +++ b/rest_registration/utils/users.py @@ -177,7 +177,7 @@ def get_user_field_obj(name: str) -> 'UserField': def get_user_setting(name: str) -> Any: - setting_name = 'USER_{name}'.format(name=name) + setting_name = f"USER_{name}" user_class = get_user_model() placeholder = object() value = getattr(user_class, name, placeholder) diff --git a/rest_registration/utils/verification.py b/rest_registration/utils/verification.py index ab4979dd..1ee048d3 100644 --- a/rest_registration/utils/verification.py +++ b/rest_registration/utils/verification.py @@ -36,7 +36,7 @@ def verify_signer_or_bad_request(signer: URLParamsSigner) -> None: def build_default_verification_url(signer: URLParamsSigner) -> str: base_url = signer.get_base_url() params = urlencode(signer.get_signed_data()) - url = '{base_url}?{params}'.format(base_url=base_url, params=params) + url = f"{base_url}?{params}" if signer.request: url = signer.request.build_absolute_uri(url) return url diff --git a/tests/doctest_utils.py b/tests/doctest_utils.py index b5e79d8f..826920c3 100644 --- a/tests/doctest_utils.py +++ b/tests/doctest_utils.py @@ -14,4 +14,4 @@ def _print_operator_test(first, second, op, fail_message_fmt): # noqa: E501 pyl first=first, second=second, operator=op) - print('FAIL:\n{fail_msg}'.format(fail_msg=fail_msg)) # noqa: T201 + print(f"FAIL:\n{fail_msg}") # noqa: T201 diff --git a/tests/helpers/api_views.py b/tests/helpers/api_views.py index b6c5207f..aef5d4e5 100644 --- a/tests/helpers/api_views.py +++ b/tests/helpers/api_views.py @@ -114,20 +114,15 @@ def _assert_response( expected_status_code=None): status_code = response.status_code if expected_status_code is not None: - msg_format = dedent("""\ + msg = dedent(f"""\ Response returned with HTTP code {status_code} but code {expected_status_code} was expected. Response body was {response.data}.""") # noqa: E501 else: - msg_format = dedent("""\ + msg = dedent(f"""\ Response unexpectedly returned with HTTP code {status_code} Response body was {response.data}.""") - msg = msg_format.format( - status_code=status_code, - expected_status_code=expected_status_code, - response=response, - ) if expected_status_code is not None: assert status_code == expected_status_code, msg elif expected_valid_response: diff --git a/tests/helpers/common.py b/tests/helpers/common.py index 73b50152..6136797a 100644 --- a/tests/helpers/common.py +++ b/tests/helpers/common.py @@ -35,17 +35,14 @@ def create_test_user(**kwargs): def assert_len_equals(collection, expected_len, msg=None): - std_msg = "{collection} does not have length {expected_len}".format( - collection=collection, - expected_len=expected_len, - ) + std_msg = f"{collection} does not have length {expected_len}" assert len(collection) == expected_len, format_assert_message(msg, std_msg) def format_assert_message(msg, standard_msg="assertion failed"): if msg is None: return standard_msg - return "{standard_msg} : {msg}".format(standard_msg=standard_msg, msg=msg) + return f"{standard_msg} : {msg}" USER_DEFAULT_FIELD_VALUES = { diff --git a/tests/helpers/email.py b/tests/helpers/email.py index 51f38e83..e2c438b3 100644 --- a/tests/helpers/email.py +++ b/tests/helpers/email.py @@ -49,9 +49,5 @@ def is_set(self): def _assert_emails_sent(sent_emails, expected_num): num_of_sent_emails = len(sent_emails) - msg_format = "Expected {expected_num} emails to be sent, but found {num_of_sent_emails}" # noqa: E501 - msg = msg_format.format( - expected_num=expected_num, - num_of_sent_emails=num_of_sent_emails, - ) + msg = f"Expected {expected_num} emails to be sent, but found {num_of_sent_emails}" assert num_of_sent_emails == expected_num, msg diff --git a/tests/helpers/testcases.py b/tests/helpers/testcases.py index 58314696..5743ce32 100644 --- a/tests/helpers/testcases.py +++ b/tests/helpers/testcases.py @@ -24,31 +24,17 @@ def create_test_user(self, **kwargs): return create_test_user(**kwargs) def assert_len_equals(self, collection, expected_len, msg=None): - std_msg_format = "{collection} does not have length {expected_len}" - std_msg = std_msg_format.format( - collection=collection, - expected_len=expected_len, - ) + std_msg = f"{collection} does not have length {expected_len}" if len(collection) != expected_len: self.fail(self._formatMessage(msg, std_msg)) def assert_is_between(self, value, start, end, msg=None): - std_msg_format = "{value} is not in range [{start}, {end})" - std_msg = std_msg_format.format( - value=value, - start=start, - end=end, - ) + std_msg = f"{value} is not in range [{start}, {end})" if not start <= value < end: self.fail(self._formatMessage(msg, std_msg)) def assert_is_not_between(self, value, start, end, msg=None): - std_msg_format = "{value} is unexpectedly in range [{start}, {end})" - std_msg = std_msg_format.format( - value=value, - start=start, - end=end, - ) + std_msg = f"{value} is unexpectedly in range [{start}, {end})" if start <= value < end: self.fail(self._formatMessage(msg, std_msg)) @@ -62,11 +48,7 @@ def _assert_mails_sent(self, expected_num): with self.capture_sent_emails() as sent_emails: yield sent_emails num_of_sent_emails = len(sent_emails) - msg_format = "Expected {expected_num} emails to be sent, but found {num_of_sent_emails}" # noqa: E501 - msg = msg_format.format( - expected_num=expected_num, - num_of_sent_emails=num_of_sent_emails, - ) + msg = f"Expected {expected_num} emails to be sent, but found {num_of_sent_emails}" # noqa: E501 self.assertEqual(num_of_sent_emails, expected_num, msg=msg) @contextlib.contextmanager @@ -98,12 +80,7 @@ def _assert_urls_in_text(self, text, expected_num, line_url_pattern): match_groupdict = match.groupdict() urls.append(match_groupdict['url']) num_of_urls = len(urls) - msg_format = "Found {num_of_urls} urls instead of {expected_num} in:\n{text}" # noqa: E501 - msg = msg_format.format( - num_of_urls=num_of_urls, - expected_num=expected_num, - text=text, - ) + msg = f"Found {num_of_urls} urls instead of {expected_num} in:\n{text}" self.assertEqual(num_of_urls, expected_num, msg=msg) return urls @@ -133,7 +110,7 @@ def setUp(self): def full_view_name(self): assert self.APP_NAME assert self.VIEW_NAME - return '{self.APP_NAME}:{self.VIEW_NAME}'.format(self=self) + return f"{self.APP_NAME}:{self.VIEW_NAME}" @property def view_url(self): diff --git a/tests/helpers/text.py b/tests/helpers/text.py index 540e85fc..2c745133 100644 --- a/tests/helpers/text.py +++ b/tests/helpers/text.py @@ -23,11 +23,6 @@ def _assert_urls_in_text(text, expected_num, line_url_pattern): match_groupdict = match.groupdict() urls.append(match_groupdict['url']) num_of_urls = len(urls) - msg_format = "Found {num_of_urls} urls instead of {expected_num} in:\n{text}" # noqa: E501 - msg = msg_format.format( - num_of_urls=num_of_urls, - expected_num=expected_num, - text=text, - ) + msg = f"Found {num_of_urls} urls instead of {expected_num} in:\n{text}" assert num_of_urls == expected_num, msg return urls diff --git a/tests/helpers/verification.py b/tests/helpers/verification.py index aa6a737b..6ae1bfcc 100644 --- a/tests/helpers/verification.py +++ b/tests/helpers/verification.py @@ -47,9 +47,9 @@ def _parse_verification_url( for key, values in query.items(): if not values: - raise ValueError("no values for '{key}".format(key=key)) + raise ValueError(f"no values for {key!r}") if len(values) > 1: - raise ValueError("multiple values for '{key}'".format(key=key)) + raise ValueError(f"multiple values for {key!r}") verification_data = {key: values[0] for key, values in query.items()} return parsed_url.path, verification_data diff --git a/tests/helpers/views.py b/tests/helpers/views.py index 85596b3a..f673e522 100644 --- a/tests/helpers/views.py +++ b/tests/helpers/views.py @@ -11,7 +11,7 @@ def __init__(self, view_name, app_name='rest_registration'): @property def full_view_name(self): - return '{self.app_name}:{self.view_name}'.format(self=self) + return f"{self.app_name}:{self.view_name}" @property def view_url(self): diff --git a/tests/unit_tests/api/views/base.py b/tests/unit_tests/api/views/base.py index 3441b9cc..57d344e2 100644 --- a/tests/unit_tests/api/views/base.py +++ b/tests/unit_tests/api/views/base.py @@ -38,11 +38,7 @@ def assert_response( self, response, expected_valid_response=True, expected_status_code=None): status_code = response.status_code - msg_format = "Response returned with code {status_code}, body {response.data}" # noqa: E501 - msg = msg_format.format( - status_code=status_code, - response=response, - ) + msg = f"Response returned with code {status_code}, body {response.data}" if expected_status_code is not None: self.assertEqual(status_code, expected_status_code, msg=msg) elif expected_valid_response: @@ -102,9 +98,9 @@ def _parse_verification_url(self, url, verification_field_names): for key, values in query.items(): if not values: - raise ValueError("no values for '{key}".format(key=key)) + raise ValueError(f"no values for {key!r}") if len(values) > 1: - raise ValueError("multiple values for '{key}'".format(key=key)) + raise ValueError(f"multiple values for {key!r}") verification_data = {key: values[0] for key, values in query.items()} return parsed_url.path, verification_data diff --git a/tests/unit_tests/api/views/register/test_register.py b/tests/unit_tests/api/views/register/test_register.py index 8590f452..99b32944 100644 --- a/tests/unit_tests/api/views/register/test_register.py +++ b/tests/unit_tests/api/views/register/test_register.py @@ -62,7 +62,7 @@ def parse_custom_verification_url(url, verification_field_names): url_path = parsed_url.path.rstrip('/') url_segments = url_path.rsplit('/', num_of_fields) if len(url_segments) != num_of_fields + 1: - raise ValueError("Could not parse {url}".format(url=url)) + raise ValueError(f"Could not parse {url!r}") data_segments = url_segments[1:] url_path = url_segments[0] + '/' diff --git a/tests/unit_tests/test_checks.py b/tests/unit_tests/test_checks.py index eb5e6514..e35420d1 100644 --- a/tests/unit_tests/test_checks.py +++ b/tests/unit_tests/test_checks.py @@ -447,8 +447,7 @@ def assert_error_codes_match(errors, expected_error_codes): expected_error_ids = sorted( code.get_full_code_id() for code in expected_error_codes) msg = "\n\nList of errors:\n" - for error in errors: - msg += "- {error}\n".format(error=error) + msg += "".join(f"- {error}\n" for error in errors) msg += " does not match the codes: " if expected_error_codes: msg += ", ".join(str(e) for e in expected_error_codes)