Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed #35537 -- Use a namedtuple for email attachments and alternatives #18261

Merged
merged 1 commit into from
Jun 20, 2024

Conversation

RealOrangeOne
Copy link
Contributor

@RealOrangeOne RealOrangeOne commented Jun 9, 2024

This makes it more descriptive to pull out the named fields

Trac ticket number

ticket-35537

Branch description

This change replaces the opaque tuples used for email attachments and alternatives with named tuples. This makes unpacking the specific indexes more descriptive, whilst avoiding breaking any existing uses (since the field order hasn't changed).

email.alternatives[0][0]  # before
email.alternatives[0].content  #after

Unpacking the alternatives doesn't seem to be documented, so there are no docs to update. Similarly, adding attachments / alternatives is done using documented methods, whose public API is unaffected by this change. Manual insertion into the .alternatives and .attachments may now fail, however users should be using the documented API methods.

Checklist

  • This PR targets the main branch.
  • The commit message is written in past tense, mentions the ticket number, and ends with a period.
  • I have checked the "Has patch" ticket flag in the Trac system.
  • I have added or updated relevant tests.
  • I have added or updated relevant docs, including release notes if applicable.
  • I have attached screenshots in both light and dark modes for any UI changes.

@sarahboyce
Copy link
Contributor

In #18279, I added some docs for EmailMultiAlternatives.
I think it would be nice to add docs for the alternatives attribute here as part of this change 👍

docs/topics/email.txt Outdated Show resolved Hide resolved
Copy link
Contributor

@sarahboyce sarahboyce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Have a last couple thoughts

Also in the 5.2 release notes, let's add something like

Email
~~~~~

* Tuple items of ``attachments`` of :class:`~django.core.mail.EmailMessage`
  and :class:`~django.core.mail.EmailMultiAlternatives` are now named tuples,
  as opposed to regular tuples.

* :attr:`EmailMultiAlternatives.alternatives
  <django.core.mail.EmailMultiAlternatives.alternatives>` is now a list of
  named tuples, as opposed to regular tuples.

docs/topics/email.txt Outdated Show resolved Hide resolved
docs/topics/email.txt Outdated Show resolved Hide resolved
docs/topics/email.txt Outdated Show resolved Hide resolved
@RealOrangeOne RealOrangeOne force-pushed the feature/email-named-tuple branch 2 times, most recently from cfa88f7 to d1005ff Compare June 19, 2024 14:03
@sarahboyce sarahboyce changed the title Use a namedtuple for email attachments and alternatives Fixed #35537 -- Use a namedtuple for email attachments and alternatives Jun 19, 2024
Copy link
Contributor

@sarahboyce sarahboyce left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you 🥳 this looks good to me

…atives.alternatives to use namedtuples.

This makes it more descriptive to pull out the named fields.
@sarahboyce sarahboyce merged commit aba0e54 into django:main Jun 20, 2024
35 checks passed
@RealOrangeOne RealOrangeOne deleted the feature/email-named-tuple branch June 20, 2024 07:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants