From b7f11f96d42ab378b49bd8bc4a69287ce9d7e7be Mon Sep 17 00:00:00 2001 From: Mike Manger Date: Mon, 25 Nov 2024 18:08:31 +0000 Subject: [PATCH] Fix a couple of pyupgrade issues (#132) --- sendgrid_backend/mail.py | 10 ++++++---- test/test_mail.py | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/sendgrid_backend/mail.py b/sendgrid_backend/mail.py index 6e6afb7..be4a400 100644 --- a/sendgrid_backend/mail.py +++ b/sendgrid_backend/mail.py @@ -67,7 +67,7 @@ class SendgridBackend(BaseEmailBackend): fail_silently = False def __init__(self, *args, **kwargs): - super(SendgridBackend, self).__init__(*args, **kwargs) + super().__init__(*args, **kwargs) # Check for the API key either in the SENDGRID_API_KEY django setting, # or passed as an argument to the init function, which takes precedence @@ -176,7 +176,9 @@ def send_messages(self, email_messages: Iterable[EmailMessage]) -> int: except HTTPError as e: message = getattr(e, "body", None) logger.error( - "Failed to send email, error: %s, response body: %s" % (e, message) + "Failed to send email, error: {}, response body: {}".format( + e, message + ) ) if not self.fail_silently: raise @@ -199,7 +201,7 @@ def set_prop(attachment, prop_name, value): else: if prop_name == "filename": prop_name = "name" - setattr(attachment, "file_{}".format(prop_name), value) + setattr(attachment, f"file_{prop_name}", value) sg_attch = Attachment() @@ -207,7 +209,7 @@ def set_prop(attachment, prop_name, value): filename = django_attch.get_filename() if not filename: ext = mimetypes.guess_extension(django_attch.get_content_type()) - filename = "part-{0}{1}".format(uuid.uuid4().hex, ext) + filename = f"part-{uuid.uuid4().hex}{ext}" set_prop(sg_attch, "filename", filename) # todo: Read content if stream? set_prop(sg_attch, "content", django_attch.get_payload().replace("\n", "")) diff --git a/test/test_mail.py b/test/test_mail.py index bb7862a..3231631 100644 --- a/test/test_mail.py +++ b/test/test_mail.py @@ -32,7 +32,7 @@ class TestMailGeneration(SimpleTestCase): @classmethod def setUpClass(self): - super(TestMailGeneration, self).setUpClass() + super().setUpClass() with override_settings( EMAIL_BACKEND="sendgrid_backend.SendgridBackend", SENDGRID_API_KEY="DUMMY_API_KEY",