Skip to content

Commit

Permalink
Fix a couple of pyupgrade issues (#132)
Browse files Browse the repository at this point in the history
  • Loading branch information
mikemanger authored Nov 25, 2024
1 parent 0ee2de4 commit b7f11f9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
10 changes: 6 additions & 4 deletions sendgrid_backend/mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -199,15 +201,15 @@ 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()

if isinstance(django_attch, MIMEBase):
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", ""))
Expand Down
2 changes: 1 addition & 1 deletion test/test_mail.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit b7f11f9

Please sign in to comment.