A set of dictionary classes that allow an aliasing of keys to other keys consistently, and a follow up implementation that does the same thing without concern for the case of string keys while preserving case for output and iteration.
Neither implementation assumes string keys, so anything Hashable
should remain compatible for all keys in the API.
It's still directly comparable (==
, in
, .get()
, etc) and access compatible with dict()
, and offers a mild framework for implementing key-transforming dictionaries somewhat painlessly with a decent test backing.
Yes, check this out.
from mmdict import MultiDict
data = {"test": "ok"}
alternatives = {"test": ["also", "as well"]}
d = MultiDict(data, aliases=alternatives)
# True
d["also"] == "ok"
# True
d["as well"] == d["test"]
from mmdict import CaselessMultiDict
d = CaselessMultiDict({"Test": "not ok"})
# A super valid write, because we're a regular dict() right?
d["Test"] = "ok"
# Oh wow, `True`, because `"Test"` and `"test"` are caselessly the same
d["test"] == "ok"
# True, because, the case of the initial write is preserved for iteration
list(d.keys()) == ["Test"]
*nix
python -mvenv .venv
. .venv/bin/activate
PowerShell
python -mvenv .venv
.\.venv\Scripts\Activate.ps1
Then, for both platforms
python -m ensurepip --upgrade
python -m pip install --upgrade pip
pip install -e .
With the virtual environment activated, use the multi-platform script to run the test suite.
script/test.sh.ps1
It's a very thin thin wrapper around bootstrapping the test run with python.