Skip to content

Conversation

@JordonPhillips
Copy link
Contributor

@JordonPhillips JordonPhillips commented Mar 11, 2025

This adds a typed context bag, which is essentially a dict with some extra type forwarding built in. It removes the need to pass around a bunch of dict[str, Any] all over the place without sacrificing the ease that doing so provides.

The intended use of this is to have statically defined typed properties, like so:

SERVICE_ID = PropertyKey(key="service_id", value_type=str)
CONFIG_PROPERTY = PropertyKey(key="config", value=Config)

...

context.properties[SERVICE_ID] = "my-service"

...

# After plugins have modified config
context.properties[CONFIG] = config

...

service_id = context.properties[SERVICE_ID]
config = context.properties[CONFIG]
endpoint = endpoints.get(service_id, {}).get(config.region)

The property keys can then be shared so that nobody messes up the key or its typing, like we do in the code generator for symbol properties.

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 March 11, 2025 14:39
@JordonPhillips JordonPhillips force-pushed the typed-context branch 2 times, most recently from 7ed59fe to 4dc7504 Compare March 11, 2025 15:26
haydenbaker
haydenbaker previously approved these changes Mar 11, 2025
alextwoods
alextwoods previously approved these changes Mar 11, 2025
Copy link
Contributor

@alextwoods alextwoods left a comment

Choose a reason for hiding this comment

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

Nice! I like this. I'll put out an update to the UserAgent to use a typed property once this is merged :-)

This adds a typed properties bag, which is essentially a dict with
some extra type forwarding built in.
@JordonPhillips
Copy link
Contributor Author

Had to rebase

@JordonPhillips JordonPhillips merged commit b042aaa into develop Mar 11, 2025
2 checks passed
@JordonPhillips JordonPhillips deleted the typed-context branch March 11, 2025 15:52
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.

4 participants