typeshed icon indicating copy to clipboard operation
typeshed copied to clipboard

Use `Self` for email.message attachments

Open srittau opened this issue 1 year ago • 4 comments

Closes: #12529

This is not a complete solution, but I think this is an improvement for any non-weird case. MIMEPart is only used as a base class of EmailMessage in the stdlib, and attachments (and other parts) are usually created via type(self):

https://github.com/python/cpython/blob/1dad23edbc9db3a13268c1000c8dd428edba29f8/Lib/email/message.py#L1175

There could be ways to cheat other non-Message parts into Messages via the payload mechanism (and we probably need to have a closer look at those again at some point), but I think this solution offers the best solution to our users, at least for now.

srittau avatar Aug 15 '24 14:08 srittau

Diff from mypy_primer, showing the effect of this PR on open source code:

dd-trace-py (https://github.com/DataDog/dd-trace-py)
+ ddtrace/internal/utils/http.py:450: error: Argument 1 to "attach" of "Message" has incompatible type "MIMEApplication"; expected "MIMEMultipart"  [arg-type]

alerta (https://github.com/alerta/alerta)
+ alerta/utils/mailer.py:45: error: Argument 1 to "attach" of "Message" has incompatible type "MIMEText"; expected "MIMEMultipart"  [arg-type]

github-actions[bot] avatar Aug 15 '24 15:08 github-actions[bot]

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

github-actions[bot] avatar Aug 15 '24 15:08 github-actions[bot]

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

github-actions[bot] avatar Aug 28 '24 14:08 github-actions[bot]

Thanks for addressing this!

butterthebuddha avatar Aug 28 '24 23:08 butterthebuddha

According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉

github-actions[bot] avatar Aug 29 '24 14:08 github-actions[bot]