typeshed icon indicating copy to clipboard operation
typeshed copied to clipboard

More accurate message types for `email` stubs

Open max-muoto opened this issue 1 year ago • 18 comments

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.

max-muoto avatar Jun 06 '24 19:06 max-muoto

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

github-actions[bot] avatar Jun 06 '24 19:06 github-actions[bot]

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

github-actions[bot] avatar Jun 06 '24 19:06 github-actions[bot]

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

github-actions[bot] avatar Jun 06 '24 19:06 github-actions[bot]

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

github-actions[bot] avatar Jun 06 '24 20:06 github-actions[bot]

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

github-actions[bot] avatar Jun 06 '24 20:06 github-actions[bot]

Policy.message_factory, Policy.__init__(message_factory), Policy.handle_defect, Policy.register_defect should use _M rather than Message.

andersk avatar Jun 07 '24 01:06 andersk

Policy.message_factory, Policy.__init__(message_factory), Policy.handle_defect, Policy.register_defect should use _M rather than Message.

Sounds good, wasn't 100% sure there. Let me fix that.

max-muoto avatar Jun 07 '24 14:06 max-muoto

Policy.message_factory, Policy.__init__(message_factory), Policy.handle_defect, Policy.register_defect should use _M rather than Message.

https://github.com/python/typeshed/pull/12104/commits/c8e29823cd24901a280afe7c98a6a7ee8a40f4d8

max-muoto avatar Jun 07 '24 14:06 max-muoto

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

github-actions[bot] avatar Jun 07 '24 15:06 github-actions[bot]

Oh and EmailPolicy.__init__(message_factory) should return EmailMessage rather than Message.

andersk avatar Jun 07 '24 18:06 andersk

Oh and EmailPolicy.__init__(message_factory) should return EmailMessage rather than Message.

https://github.com/python/typeshed/pull/12104/commits/85ed29568738dc642f913c0a8482ab22407aaf78

max-muoto avatar Jun 07 '24 20:06 max-muoto

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

github-actions[bot] avatar Jun 07 '24 20:06 github-actions[bot]

@srittau It seems like you looked into making Policy generic at some point? Do you maybe want to review here?

max-muoto avatar Jun 08 '24 18:06 max-muoto

Sorry to bug, but just wanted to follow-up again @srittau, or if maybe someone else is able to take a look.

max-muoto avatar Jul 13 '24 15:07 max-muoto

LGTM, a few optional suggestions below.

Thanks, accepted all of your suggestions.

max-muoto avatar Jul 15 '24 16:07 max-muoto

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]

github-actions[bot] avatar Jul 15 '24 16:07 github-actions[bot]

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.

srittau avatar Jul 15 '24 17:07 srittau

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.

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.

max-muoto avatar Jul 15 '24 17:07 max-muoto

Closing until I have time to take a look at this again.

max-muoto avatar Sep 08 '24 03:09 max-muoto