Skip to content

Commit e133509

Browse files
test(json_decoder): regression test for simplejson encoding-kwarg tolerance (#15)
Guards the e49c9cb fix that swallows simplejson's obsolete encoding= kwarg (injected by requests via simplejson on Python 3.9+, rejected by stdlib json.JSONDecoder). The fix was untested until now; a live BfxLendingBot deploy of v6.0.1 (which predates e49c9cb) crashed on init with this exact TypeError, motivating a v6.0.2 release plus this guard. Co-authored-by: cloudingenium-automation[bot] <cloudingenium-automation[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 353b89e commit e133509

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

tests/test_json_decoder.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,12 @@ def test_mixed_content(self):
5555
'{"orderId": 123, "items": [1, 2, 3]}', cls=JSONDecoder
5656
)
5757
assert result == {"order_id": 123, "items": [1, 2, 3]}
58+
59+
def test_tolerates_simplejson_encoding_kwarg(self):
60+
# Regression: `requests` routes response.json(cls=JSONDecoder) through
61+
# simplejson when python3-simplejson is installed, and simplejson.loads
62+
# injects an obsolete `encoding=` kwarg that stdlib json.JSONDecoder
63+
# rejects on Python 3.9+ (TypeError). The decoder must swallow it.
64+
# Without kwargs.pop("encoding", ...) constructing this raises TypeError.
65+
decoder = JSONDecoder(encoding="utf-8")
66+
assert decoder.decode('{"firstName": "John"}') == {"first_name": "John"}

0 commit comments

Comments
 (0)