Skip to content

Conversation

@JordonPhillips
Copy link
Contributor

This updates the design for traits from being simple bags of loosely typed data. Now traits may instead have concrete implementations that are discoverable dynamically simply by implementing the relevant subclass.

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 February 28, 2025 15:58
nateprewitt
nateprewitt previously approved these changes Feb 28, 2025
get_payload_member,
)
from .traits import EVENT_HEADER_TRAIT
from smithy_core.traits import EventHeaderTrait
Copy link
Contributor

Choose a reason for hiding this comment

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

Just for my understanding, is the EventHeaderTrait ever used outside of an Event Stream implementation? Is this just being ported back to consolidate all the traits together or is there another theoretical library we'd use this in?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is only ever used by event streams, yes. But it could be used if we had an alternative event stream format or something like that. I've kept all the traits in core because so far we're only using traits from Smithy's default set of traits. But we could conceivably split them up too.

This updates traits to use a dynamic registry to allow concrete
implementations to be automatically discovered and created when
constructing schemas.
@JordonPhillips
Copy link
Contributor Author

had to rebase

comfortable to use, providing better typed accessors to data or even relevant
utility functions.

Both kinds of traits implement an inherent `Protocol` - they both have the `id`
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice!

def expect_trait(self, t: ShapeID) -> "Trait | DynamicTrait": ...

def expect_trait(self, t: "type[Trait] | ShapeID") -> "Trait | DynamicTrait":
"""Get a trait based on it's ShapeID or class.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
"""Get a trait based on it's ShapeID or class.
"""Get a trait based on its ShapeID or class.

@JordonPhillips JordonPhillips merged commit b0d52aa into develop Mar 4, 2025
1 check passed
@JordonPhillips JordonPhillips deleted the power-traits branch March 4, 2025 18:52
nateprewitt added a commit that referenced this pull request Mar 4, 2025
nateprewitt added a commit that referenced this pull request Mar 4, 2025
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