Merged
Conversation
When encoding nested lists (e.g. [[1, 2], [3, 4]]), there was no code path to handle list elements that are themselves lists. They fell through to the else branch and were stringified as raw Python list objects, producing `items[0]=[1, 2]` instead of `items[0][0]=1&items[0][1]=2`. Fix by adding a recursive branch for list/tuple elements. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Committed-By-Agent: claude
There was a problem hiding this comment.
Pull request overview
Fixes form-parameter encoding for nested lists (2D arrays) so list elements that are themselves lists/tuples are recursively encoded with indexed keys instead of being stringified as raw Python lists.
Changes:
- Add nested list/tuple handling in
_api_encodeto recurse via_encode_nested_dictusing enumerated indices. - Add a regression test asserting correct
items[0][0]-style encoding for 2D arrays.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
stripe/_encode.py |
Adds an elif isinstance(sv, (list, tuple)) branch to properly encode nested arrays with double indices. |
tests/test_encode.py |
Adds regression coverage for nested list encoding output ordering and key format. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
prathmesh-stripe
approved these changes
Apr 1, 2026
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> Committed-By-Agent: claude
prathmesh-stripe
approved these changes
Apr 1, 2026
Contributor
prathmesh-stripe
left a comment
There was a problem hiding this comment.
Need formatting but looks good
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?
When encoding nested lists (e.g.
[[1, 2], [3, 4]]) as form parameters, there was no code path to handle list elements that are themselves lists. They fell through to theelsebranch and were stringified as raw Python list objects, producingitems[0]=[1, 2]instead of the correctitems[0][0]=1&items[0][1]=2.What?
elif isinstance(sv, (list, tuple))branch instripe/_encode.pythat recurses via_encode_nested_dicttests/test_encode.pySee Also
Changelog