The profile field is a list that contains a compliance URI and a structured object, which is how it’s represented in an info.json blob – but that leads to somewhat weird-looking code like:
This is the refactoring that arose from trying to do that, plus the usual battery of extra tests.
Some notes:
We're trading some extra complexity in img_info.py for cleaner code elsewhere. That’s not a definite win, but I think it’s at least worth consideration.
I split out from_json() into two method: one that just takes JSON strings, another that reads them from disk. This makes writing tests easier.
This adds a new dependency on attrs, because I didn't want to write any class boilerplate. I find attrs pretty useful, and if we’re happy to add it as dependency (pure Python), I think it might be useful elsewhere.
The
profile
field is a list that contains a compliance URI and a structured object, which is how it’s represented in aninfo.json
blob – but that leads to somewhat weird-looking code like:I think it’s clearer to write:
This is the refactoring that arose from trying to do that, plus the usual battery of extra tests.
Some notes:
We're trading some extra complexity in
img_info.py
for cleaner code elsewhere. That’s not a definite win, but I think it’s at least worth consideration.I split out
from_json()
into two method: one that just takes JSON strings, another that reads them from disk. This makes writing tests easier.This adds a new dependency on attrs, because I didn't want to write any class boilerplate. I find attrs pretty useful, and if we’re happy to add it as dependency (pure Python), I think it might be useful elsewhere.