chore: introduce typed context keys - #2677
Open
xlgmokha wants to merge 1 commit into
Open
Conversation
xlgmokha
force-pushed
the
xlgmokha/context-key-refactor
branch
from
August 4, 2026 22:11
c0394f3 to
3efb7ce
Compare
This comment has been minimized.
This comment has been minimized.
xlgmokha
force-pushed
the
xlgmokha/context-key-refactor
branch
from
August 5, 2026 15:46
bd0276f to
d270ecd
Compare
xlgmokha
force-pushed
the
xlgmokha/context-key-refactor
branch
6 times, most recently
from
August 5, 2026 18:45
079a840 to
ed3e119
Compare
xlgmokha
force-pushed
the
xlgmokha/context-key-refactor
branch
from
August 5, 2026 19:37
ed3e119 to
47d4baa
Compare
* Add `xcontext.Key[T]`, a generic context key that carries its own With/From accessors. * Drops functionHooksKey, which had no readers or writers. * Where a wrongly typed value once panicked it now returns the zero value.
xlgmokha
force-pushed
the
xlgmokha/context-key-refactor
branch
from
August 5, 2026 19:43
47d4baa to
3cf9670
Compare
xlgmokha
marked this pull request as ready for review
August 5, 2026 19:52
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What kind of change does this PR introduce?
Refactoring. This change adds a typed context key that can be used to add an item to context and fetch it safely.
What is the current behavior?
Each read from
context.Contextwith an unchecked type assertion can panics if the value is the wrong type.Before:
What is the new behavior?
After:
Additional context