Skip to content
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

refactor: use EmailMessage class #142

Merged
merged 1 commit into from
Sep 13, 2024

Conversation

henryiii
Copy link
Collaborator

@henryiii henryiii commented Sep 12, 2024

Make RFC822 a subclass of EmailMessage and remove all reliance on custom behaviors.

Close #101.

@henryiii
Copy link
Collaborator Author

Will need to see if we have anyone using this API, so we know if we need back compat.

@henryiii
Copy link
Collaborator Author

I don't see anyone doing more than bytes and occasionally str, so I think we can drop the old attributes, and bring them back with a deprecation warning if someone needs them.

@henryiii henryiii force-pushed the henryiii/refactor/message branch 2 times, most recently from e7f2f1f to c0b5af7 Compare September 12, 2024 18:55
@henryiii henryiii changed the title refactor: closer to EmailMessage class refactor: use EmailMessage class Sep 12, 2024
@henryiii
Copy link
Collaborator Author

Here's the 30 usages I could find:

https://github.com/search?type=code&q=path%3A.py+%28%22import+pyproject_metadata%22+OR+%22from+pyproject_metadata%22%29+NOT+is%3Afork

(Quite a few are actually forks or copies that GitHub doesn't know are forks)

I think dropping .headers and .body is safe, not seeing usages of it, I think it's an internal detail.

def items(self) -> list[tuple[str, str]]:
return self._headers.copy()
If a value is None, do nothing.
If a value contains a newline, indent it (may produce a warning in the future).
Copy link
Contributor

Choose a reason for hiding this comment

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

Uh? Do we actually need this? Why? Does this even work with EmailMesage? I would not be surprised if it normalized whitespace in headers or encode it somehow. Anyhow, how do multi-line strings end up here?

Copy link
Collaborator Author

@henryiii henryiii Sep 12, 2024

Choose a reason for hiding this comment

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

It produces the same thing we produce now. It was added in #2, and pretty sure it mostly shows up with multiline summaries:

I think we could add a warning when one is detected, and then not include the behavior if we can make backward incompatible changes (#140).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(Note that in #2, the extended mechanism is only for the description, which is now in the body instead, and the actual mechanism included pipe chars).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

(and in scikit-build-core I manually disallow multiline summaries)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

And you can actually read these multiline strings with email.parse, I did check it, it keeps the indention. Without indentation, they don't work, of course.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I pulled out and merged the preparation steps, so you can see just the move by itself.

@henryiii
Copy link
Collaborator Author

pre-commit.ci autofix

@henryiii henryiii merged commit 5966114 into pypa:main Sep 13, 2024
22 checks passed
@henryiii henryiii deleted the henryiii/refactor/message branch September 13, 2024 03:39
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.

Use email.message.Message instead of rolling own (RFC822Message)
2 participants