biocore / biocore/microsetta-private-api
Object hooks and isinstance tests
- Dominant language
- Python
- Stars
- 6
- Forks
- 18
- PR merge metrics
- No merged PRs in 30d
Description
In `model/source.py` there are a few JSON decoder hooks specified. These currently perform `isinstance` checks against `dict` (e.g., in [`human_decoder`](https://github.com/biocore/microsetta-private-api/blob/master/model/source.py#L5)). Are these tests necessary? In the example below, the hook only appears to be used if the item coming in is a JSON object represented already as a `dict`:
```python
$ ipython
Python 3.6.7 | packaged by conda-forge | (default, Feb 28 2019, 02:16:08)
Type 'copyright', 'credits' or 'license' for more information
IPython 7.9.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import json
In [2]: def hook(item):
...: print(type(item))
...: return item
...:
In [3]: json.loads('{"foo": "bar"}', object_hook=hook)
Out[3]: {'foo': 'bar'}
In [4]: json.loads('"foo"', object_hook=hook)
Out[4]: 'foo'
In [5]: json.loads('["foo", "bar"]', object_hook=hook)
Out[5]: ['foo', 'bar']
```
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.