improve types for metadata and other dict-like types#1785
Merged
Conversation
metadata and other dict-like types
jar-stripe
approved these changes
Apr 1, 2026
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.
Why?
In #1762 we changed
StripeObjectto no longer bedicts. But, there are many places where we refer to generated map-like types as dicts (likemetadata). Those need to be updated to communicate that they're stripe objects at runtime, but not be picky about potential type errors.Enter the
UntypedStripeObject. It's a small manual class that exposes its__getattr__function (instead of hiding it behind anif TYPE_CHECKINGblock, likeStripeObjectdoes). As a result, it'll never show a type error for key access (just like a normal dict). Note that this exists purely for typecheking, so it has no runtime implications. It's just used to more accurately represent the shape of metadataFor reviewers
The manual change is the new class definition in
_stripe_objectand its associated tests. Everything else is codegen.What?
UntypedStripeObjectassert_typeis available in all supportedtyping_extensionversions now, so move it out of linting jailSee Also
metadataandEvent.data.objectdon't match runtime types #1782StripeObjectno longer inherits fromdict#1762