Repository navigation
Allow customizing JSONDisk serialization with subclass hooks - #377
Gonghan-Princess wants to merge 1 commit 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. |
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.