Extract multipart data callbacks into a method

Closed
KL
3d ago
+90-53

Move MultipartParser's data_callback closure into _data_callback, with data and length passed explicitly instead of captured on each write(). This takes one part of the proposal in #368, leaving the header-size checks and other closures unchanged. Pin the benchmark workflow to Python 3.13.18, the patch release used by the initial CI run, to prevent interpreter drift.

Add a public-API regression test for callback order and data across chunk boundaries, including failed boundary matches. Validation: scripts/check, scripts/test --strict-config --strict-markers (217 tests, 100% coverage), and scripts/rename pass.

Local microbenchmarks on CPython 3.13.4, macOS arm64 (µs per parse; median of three interleaved comparisons, each taking the best of seven timeit batches with the existing benchmark inputs):

InputmainExtraction onlyChange
Small form8.397.99-4.8%
Large form336.69326.89-2.9%
8 MB upload575.58567.51-1.4%
Boundary-heavy data44.4344.52+0.2%

These are local microbenchmark results, not end-to-end request timings. The initial CodSpeed simulation reported no performance change across all five benchmarks, so a portable speedup is not established.

Session: pi --session 01a1e0a2-78a9-7473-86ce-b992bd92cf74