-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Add PEP 714 support for JSON API client #3698
Conversation
c449d18
to
12c6e79
Compare
Oh interesting, Serde does not treat aliases as fallbacks. They're mutually exclusive. |
12c6e79
to
07a4c66
Compare
pub dist_info_metadata: Option<DistInfoMetadata>, | ||
pub data_dist_info_metadata: Option<DistInfoMetadata>, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Repeating like this is the only way I could figure out to support multiple aliases under different names, where multiple values can be present. (PyPI serves both core-metadata
and data-dist-info-metadata
; serde's alias
feature errors if multiple values are present.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Per PEP 714, we could omit data_dist_info_metadata
... But there may be registries that only serve that in practice, since that's what pip did for a while.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would define a separate wire type with what you want to support, and then implement From<FileWire> for File
(or TryFrom
if needed). Then use #[serde(from = "FileWire")]
. That way, you can resolve the aliases down to one field at deserialization time, and avoid spreading that complexity outward to anyone consuming File
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, but we already have a separate File
type that we use in our own abstractions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So in a sense this is FileWire
. And we have a From
elsewhere.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah I was confused because I wouldn't normally expect a wire type to have pub
fields and otherwise be exported. Basically, my suggestion boils down to "encapsulate the aliases at the deserialization boundary." But if the point of File
is to be the boundary and be exposed to the world, then yeah, I think what you have is fine.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah this is meant to be roughly "the exact JSON we get from the API", so I suppose this is ok.
07a4c66
to
62a10f1
Compare
Summary
Closes #3689.
Test Plan
Manually verified we pick up
core-metadata
from PyPI if I remove the aliases.