Skip to content

Fix str / repr for StripeObjects with decimals & add support for plain dicts#1780

Merged
xavdid-stripe merged 4 commits intomasterfrom
RUN_DEVSDK-2303
Mar 31, 2026
Merged

Fix str / repr for StripeObjects with decimals & add support for plain dicts#1780
xavdid-stripe merged 4 commits intomasterfrom
RUN_DEVSDK-2303

Conversation

@xavdid-stripe
Copy link
Copy Markdown
Contributor

@xavdid-stripe xavdid-stripe commented Mar 30, 2026

Why?

We added support for native decimal types in #1769 but our code for stringifying objects for printing didn't account for it. (API requests handled it as expected). To fix, we cenralized our serialization logic so that both paths (which both end up sending things to JSON) use the same logic.

While I was in there, the user requested being able to get a JSON-dumpable dict that isn't yet a string. Since we have all the code to do that already, I added an arg to support it.

While I was in here, I simplified the way we're encoding things into JSON. Typechecks in python are a little expensive, so I tried to minimize the number of places we do those checks. I think there's more to do here, but it's internal, so there's no rush.

What?

  • Reuse existing JSON encoding logic in to_dict
  • add for_json kwarg to to_dict()
  • tweaked encoding logic to share a little more code

See Also

#1779

@xavdid-stripe xavdid-stripe requested a review from a team as a code owner March 30, 2026 23:02
@xavdid-stripe xavdid-stripe requested review from mbroshi-stripe and removed request for a team March 30, 2026 23:02
@xavdid-stripe xavdid-stripe changed the title fix serialization of decimals Fix JSON serialization (and str / repr) for objects with decimals Mar 30, 2026
@xavdid-stripe xavdid-stripe enabled auto-merge (squash) March 30, 2026 23:13
@xavdid-stripe xavdid-stripe disabled auto-merge March 30, 2026 23:31
@xavdid-stripe xavdid-stripe changed the title Fix JSON serialization (and str / repr) for objects with decimals Fix JSON serialization (and str / repr) for objects with decimals & add support for plain dicts Mar 31, 2026
@xavdid-stripe xavdid-stripe enabled auto-merge (squash) March 31, 2026 00:29
Copy link
Copy Markdown
Contributor

@mbroshi-stripe mbroshi-stripe left a comment

Choose a reason for hiding this comment

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

Looks good!

@xavdid-stripe xavdid-stripe merged commit 38deb0b into master Mar 31, 2026
16 checks passed
@xavdid-stripe xavdid-stripe deleted the RUN_DEVSDK-2303 branch March 31, 2026 17:25
@xavdid-stripe xavdid-stripe changed the title Fix JSON serialization (and str / repr) for objects with decimals & add support for plain dicts Fix str / repr for StripeObjects with decimals & add support for plain dicts Mar 31, 2026
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