Skip to content

improve types for metadata and other dict-like types#1785

Merged
xavdid merged 4 commits intomasterfrom
RUN_DEVSDK-2306
Apr 1, 2026
Merged

improve types for metadata and other dict-like types#1785
xavdid merged 4 commits intomasterfrom
RUN_DEVSDK-2306

Conversation

@xavdid
Copy link
Copy Markdown
Contributor

@xavdid xavdid commented Apr 1, 2026

Why?

In #1762 we changed StripeObject to no longer be dicts. But, there are many places where we refer to generated map-like types as dicts (like metadata). 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 an if TYPE_CHECKING block, like StripeObject does). 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 metadata

For reviewers

The manual change is the new class definition in _stripe_object and its associated tests. Everything else is codegen.

What?

  • write UntypedStripeObject
  • add type tests
  • codegen that into a ton of places
  • tweak changelog to be more accurate
  • assert_type is available in all supported typing_extension versions now, so move it out of linting jail

See Also

@xavdid xavdid requested a review from a team as a code owner April 1, 2026 00:21
@xavdid xavdid requested review from jar-stripe and removed request for a team April 1, 2026 00:21
@xavdid xavdid changed the title improve types for metadata and other dict-like types improve types for metadata and other dict-like types Apr 1, 2026
@xavdid xavdid enabled auto-merge (squash) April 1, 2026 17:21
@xavdid xavdid merged commit 628da69 into master Apr 1, 2026
17 checks passed
@xavdid xavdid deleted the RUN_DEVSDK-2306 branch April 1, 2026 17:37
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.

2 participants