8000 extmod/modjson: Add default argument for json.dump(s). by alectric-tr · Pull Request #18530 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

Conversation

@alectric-tr
Copy link
Contributor

Summary

As mentioned in the issue, the CPython api for json.dump and json.dumps allows for the named argument default to be provided. It is a callable type that specifies a way for non-serializable objects to be serialized. This patch series adds support for this argument in Micropython along with the documentation update and extending tests to cover the new argument.

CPython reference: https://docs.python.org/3/library/json.html

default (callable | None) – A function that is called for objects that can’t otherwise be serialized. It should return a JSON encodable version of the object or raise a TypeError. If None (the default), TypeError is raised.

Fixes: #16963

Testing

Tested on the Unix port.

@alectric-tr alectric-tr force-pushed the feat/json_dump_default_arg_support branch from 37af00f to 697fc88 Compare December 7, 2025 23:41
@github-actions
Copy link
github-actions bot commented Dec 7, 2025

Code size report:

Reference:  esp32/main: Update esp_hosted component to latest version 2.7.0. [7702f7f]
Comparison: tests: Add testing files covering default arg for json dump(s). [merge of 9c93046]
  mpy-cross:  +128 +0.034% 
   bare-arm:   +36 +0.064% 
minimal x86:   +58 +0.031% 
   unix x64:  +232 +0.027% standard
      stm32:  +128 +0.032% PYBV10
     mimxrt:  +136 +0.036% TEENSY40
        rp2:  +144 +0.016% RPI_PICO_W
       samd:  +160 +0.059% ADAFRUIT_ITSYBITSY_M4_EXPRESS
  qemu rv32:  +160 +0.035% VIRT_RV32

@alectric-tr alectric-tr force-pushed the feat/json_dump_default_arg_support branch from 697fc88 to 604b8bc Compare December 7, 2025 23:57
@codecov
Copy link
codecov bot commented Dec 8, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 98.38%. Comparing base (7702f7f) to head (9c93046).
⚠️ Report is 1 commits behind head on master.

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #18530   +/-   ##
=======================================
  Coverage   98.38%   98.38%           
=======================================
  Files         171      171           
  Lines       22300    22312   +12     
=======================================
+ Hits        21939    21951   +12     
  Misses        361      361           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@alectric-tr alectric-tr force-pushed the feat/json_dump_default_arg_support branch 4 times, most recently from 848d5a5 to bf0d3d7 Compare December 8, 2025 01:04
Signed-off-by: Alex Tran <alex.t.tran@gmail.com>
Signed-off-by: Alex Tran <alex.t.tran@gmail.com>
Signed-off-by: Alex Tran <alex.t.tran@gmail.com>
@alectric-tr alectric-tr force-pushed the feat/json_dump_default_arg_support branch from bf0d3d7 to 9c93046 Compare December 8, 2025 01:39
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.

suggestion: json.dump() does not support default keyword argument

1 participant

0