my.core.serialize: simplejson support, more types (#176)
* my.core.serialize: simplejson support, more types I added a couple extra checks to the default function, serializing datetime, dates and dataclasses (incase orjson isn't installed) (copied from below) if orjson couldn't be imported, try simplejson This is included for compatibility reasons because orjson is rust-based and compiling on rarer architectures may not work out of the box as an example, I've been having issues getting it to install on my phone (termux/android) unlike the builtin JSON modue which serializes NamedTuples as lists (even if you provide a default function), simplejson correctly serializes namedtuples to dictionaries this just gives another option to people, simplejson is pure python so no one should have issues with that. orjson is still way faster, so still preferable if its easy and theres a precompiled build for your architecture (which there typically is) If you're ever running this with simplejson installed and not orjson, its pretty easy to tell as the JSON styling is different; orjson has no spaces between tokens, simplejson puts spaces between tokens. e.g. simplejson: {"a": 5, "b": 10} orjson: {"a":5,"b":10}
This commit is contained in:
parent
821bc08a23
commit
46198a6447
3 changed files with 67 additions and 9 deletions
11
tox.ini
11
tox.ini
|
@ -23,6 +23,13 @@ commands =
|
|||
setenv = MY_CONFIG = nonexistent
|
||||
commands =
|
||||
pip install -e .[testing]
|
||||
|
||||
# installed to test my.core.serialize while using simplejson and not orjson
|
||||
pip install simplejson
|
||||
python3 -m pytest \
|
||||
tests/serialize_simplejson.py \
|
||||
{posargs}
|
||||
|
||||
pip install cachew
|
||||
pip install orjson
|
||||
|
||||
|
@ -43,7 +50,9 @@ commands =
|
|||
python3 -m pytest tests \
|
||||
# ignore some tests which might take a while to run on ci..
|
||||
--ignore tests/takeout.py \
|
||||
--ignore tests/extra/polar.py
|
||||
--ignore tests/extra/polar.py \
|
||||
# dont run simplejson compatability test since orjson is now installed
|
||||
--ignore tests/serialize_simplejson.py
|
||||
{posargs}
|
||||
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue