More accurate message types for `email` stubs
Fix long-standing email.parser issues detailed in https://github.com/python/typeshed/issues/2417 and https://github.com/python/typeshed/issues/10762
This takes the approach recommended by @andersk and utilizies generic defaults to help us get accurate types accounting for the default arguments here without any overloads.
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. 🤖🎉
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. 🤖🎉
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉
Policy.message_factory, Policy.__init__(message_factory), Policy.handle_defect, Policy.register_defect should use _M rather than Message.
Policy.message_factory,Policy.__init__(message_factory),Policy.handle_defect,Policy.register_defectshould use_Mrather thanMessage.
Sounds good, wasn't 100% sure there. Let me fix that.
Policy.message_factory,Policy.__init__(message_factory),Policy.handle_defect,Policy.register_defectshould use_Mrather thanMessage.
https://github.com/python/typeshed/pull/12104/commits/c8e29823cd24901a280afe7c98a6a7ee8a40f4d8
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉
Oh and EmailPolicy.__init__(message_factory) should return EmailMessage rather than Message.
Oh and
EmailPolicy.__init__(message_factory)should returnEmailMessagerather thanMessage.
https://github.com/python/typeshed/pull/12104/commits/85ed29568738dc642f913c0a8482ab22407aaf78
According to mypy_primer, this change has no effect on the checked open source code. 🤖🎉
@srittau It seems like you looked into making Policy generic at some point? Do you maybe want to review here?
Sorry to bug, but just wanted to follow-up again @srittau, or if maybe someone else is able to take a look.
LGTM, a few optional suggestions below.
Thanks, accepted all of your suggestions.
Diff from mypy_primer, showing the effect of this PR on open source code:
setuptools (https://github.com/pypa/setuptools)
+ setuptools/command/bdist_wheel.py:591: error: Argument "policy" to "Generator" has incompatible type "EmailPolicy"; expected "Optional[Policy[Message[str, str]]]" [arg-type]
Looking at the new primer hit, I think we need to make EmailMessage generic, too: class EmailMessage(MIMEPart[_HeaderRegistryT, _HeaderRegistryParamT]): ....
Although I have to admit, I'm a bit lost in how all these classes work together.
Looking at the new primer hit, I think we need to make
EmailMessagegeneric, too:class EmailMessage(MIMEPart[_HeaderRegistryT, _HeaderRegistryParamT]): ....Although I have to admit, I'm a bit lost in how all these classes work together.
I'll take another deeper look in the next day or two, since it's a been a while since I worked on this originally now haha.
Closing until I have time to take a look at this again.