Skip to content

Make email.message.Message generic over the header type #11732

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

Merged
merged 12 commits into from
Apr 23, 2024

Conversation

srittau
Copy link
Collaborator

@srittau srittau commented Apr 8, 2024

No description provided.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

This comment has been minimized.

@srittau
Copy link
Collaborator Author

srittau commented Apr 8, 2024

The email/http Message/Header class hierarchy is quite "creative".

This comment has been minimized.

@srittau srittau marked this pull request as ready for review April 8, 2024 11:29

This comment has been minimized.

Copy link
Collaborator

@Avasam Avasam left a comment

Choose a reason for hiding this comment

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

A small adjustment for a comment mentioning the Any trick, otherwise this looks good to me.

Copy link
Contributor

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

spack (https://github.com/spack/spack)
- lib/spack/spack/oci/oci.py:142: error: Argument 1 to "endpoint" of "ImageReference" has incompatible type "str | None"; expected "str"  [arg-type]

@srittau srittau requested a review from Avasam April 23, 2024 08:36
@Avasam Avasam merged commit 56db30e into python:main Apr 23, 2024
54 checks passed
@srittau srittau deleted the email-generic branch April 23, 2024 19:21
@embray
Copy link

embray commented Jul 22, 2024

This seems to have introduced a regression for me at least on Python 3.10, not sure if it works better on say 3.12...

This results in an error:

from email.header import Header
from email.mime.multipart import MIMEMultipart

msg = MIMEMultipart('mixed')
msg['Subject'] = Header('Subject...')
$ mypy --version
mypy 1.11.0 (compiled: yes)
$ mypy .tests/typing/mime.py 
.tests/typing/mime.py:5: error: Incompatible types in assignment (expression has type "Header", target has type "str")  [assignment]

Not clear how this should be typed anymore. If I try to do MIMEMultipart[str, Header] I just get "type[MIMEMultipart]" is not generic and not indexable. I think the default typevars still need to be supplied in the subclasses as well.

I'll set to ignore for now but just as a heads-up.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants