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

Add deserializer interfaces and document implementation of them #246

Merged
merged 4 commits into from
May 23, 2024

Conversation

JordonPhillips
Copy link
Contributor

@JordonPhillips JordonPhillips commented May 17, 2024

Depends on #245

This adds interfaces for shape deserializers, as well as document implementations for those interfaces. See #245 for additional context on why this approach is being taken.

Another advantage with both document serializers and deserializers available is a sort of compatibility layer with botocore:

botocore_style_input: dict[str, Any] = {"foo": "bar"}
smithy_style_input: InputShape = Document(botocore_style).as_shape(InputShape)

smithy_style_output: OutputShape = OutputShape(foo="bar")
botocore_style_output: dict[str, Any] = Document.from_shape(smithy_style_output).as_value()

There will of course be some cases where this won't work, mostly regarding cases where botocore has customized the type or name of a parameter, but for the vast majority of inputs and outputs, this should work. We could write a compatibility package that addresses those extra cases if needed.

In this way people could migrate gradually without much difficulty.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@JordonPhillips JordonPhillips requested a review from a team as a code owner May 17, 2024 12:35
@JordonPhillips JordonPhillips changed the title Deserializer interfaces Add deserializer interfaces and document implementation of them May 17, 2024
match schema.expect_member_index():
case 0:
kwargs["boolean_member"] = de.read_boolean(
SCHEMA.members["booleanMember"]
Copy link
Member

Choose a reason for hiding this comment

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

This is a test case, but in actual generated types, generating member schemas so that you can reference them directly from deserializers would avoid the overhead of hashing and getting the schema from a hashmap. Looking up schemas in the hashmap is kind of canceling out the benefit of deserializing based on the generated member index. I think you'd want those to be _ or even __ prefixed.

Copy link
Contributor Author

@JordonPhillips JordonPhillips May 18, 2024

Choose a reason for hiding this comment

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

In Python, property access is usually just a dict access, so there's no real difference. I'll be experimenting with slots to speed that up, but it'll add a good bit of generated code

mtdowling
mtdowling previously approved these changes May 20, 2024
@JordonPhillips JordonPhillips force-pushed the deserializer-interfaces branch from f2d4126 to 29d0513 Compare May 21, 2024 08:52
nateprewitt
nateprewitt previously approved these changes May 22, 2024
Base automatically changed from serializer-interfaces to develop May 23, 2024 13:44
@JordonPhillips JordonPhillips dismissed stale reviews from nateprewitt and mtdowling May 23, 2024 13:44

The base branch was changed.

@JordonPhillips JordonPhillips force-pushed the deserializer-interfaces branch from 29d0513 to 2ab5a3d Compare May 23, 2024 13:46
@JordonPhillips
Copy link
Contributor Author

Had to rebase

@JordonPhillips JordonPhillips merged commit 6ac6024 into develop May 23, 2024
5 checks passed
@JordonPhillips JordonPhillips deleted the deserializer-interfaces branch May 23, 2024 15:59
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.

3 participants