Use `Self` for email.message attachments
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.
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]
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉
Thanks for addressing this!
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉