Repository navigation
Allow customizing JSONDisk serialization with subclass hooks - #377
Gonghan-Princess wants to merge 3 commits into
Conversation
|
Small negative-test companion to the working-hook cases: test-only commit. It's one new file with no implementation changes. Four cases reject a key or replacement value, with inline and file-backed storage. They check that the hook's I ran the unchanged test bodies against the complete pinned core modules on Windows/Python 3.14.4, SQLite 3.50.4. All four pass with this branch. On the base, all four rejection checks fail because the new hook attributes are ignored. That's a feature-boundary check, not a claim that ordinary baseline writes are corrupt. Two useful guards here: rejection before persistence, and cold readback in both storage modes. Focused Ruff checks pass; I haven't run the full Django/package suite, tox, coverage matrix, or Blue/Flake8/isort toolchain. Take whichever cases help. |
|
Adopted your four cases in 98adfc0, preserving your author credit, with a Blue-only formatting follow-up in da3437f. These add rejection/persistence coverage absent from the existing hook tests; no implementation changes were needed. Local macOS/Python 3.9.6 validation: 14 focused tests passed; the full Django/package and doctest suite passed all 265 tests with 99.03% coverage. Blue, Flake8 and isort pass for the new file. Against the upstream base, the same four cases fail at the expected ValueError checks because the base ignores the hooks; this verifies the feature boundary, without suggesting ordinary baseline writes corrupt data. GitHub workflow 39191234466 is currently completed/action_required before any jobs ran, so the new head has no passing GitHub CI result yet. |
Summary
Refs #285 and follows the maintainer's proposed subclass hooks rather than adding constructor arguments.
JSONDisk.json_dumpsandJSONDisk.json_loadsas static callable attributes and use them consistently for both keys and values.read=Truestream handling unchanged.staticmethodcustomization and the requirement to reuse compatible serialization when reopening a cache.The hooks intentionally retain the standard-library string contract: dump returns
str, load receivesstr. Byte-returning serializers can be adapted by decoding in the dump hook; this does not introduce native byte-returning hooks or a new dependency.Validation
Tested on Windows with Python 3.12.10 and Django 4.2.30, using
DJANGO_SETTINGS_MODULE=tests.settingsandPYTHONPATHpointing at this checkout:python -m pytest tests/test_jsondisk.py -o addopts='' -q: 10 passed.python -m pytest -n 2: 261 passed, 99.13% branch-aware coverage (98% required).Known tooling output: Django emits its existing
USE_L10Ndeprecation warning, and Blue's Click integration emits duplicate-option warnings. No failures were ignored. Other Python versions were not run locally.Documentation and scope
The tutorial and API docstring describe the new user-facing hooks. This repository has no current release-note file or README latest-update convention, so no new release-history format was introduced. No dependency or unrelated changes.
AI assistance
AI assisted with implementation, regression tests, local validation, and this PR description. The contributor remains responsible for the submission. No third-party code was copied and no additional runtime dependency was introduced.