digitalbazaar / pyld

JSON-LD processor written in Python
https://json-ld.org/
Other
611 stars 131 forks source link

jsonld.expand() fails if the document contains a value which does not plainly serialize to JSON #146

Open anatoly-scherbakov opened 3 years ago

anatoly-scherbakov commented 3 years ago
from pyld import jsonld
from datetime import date

jsonld.expand({'@context': {'@vocab': 'https://schema.org/'}, '@id': 'https://example.blog/post', 'publicationDate': datetime.date(2021, 1, 11)})

Which gives:

...
  File "{venv}/lib/python3.8/site-packages/pyld/jsonld.py", line 3523, in _expand_value
    if not (_is_bool(value) or _is_numeric(value) or _is_string(value)):
  File "{venv}/lib/python3.8/site-packages/pyld/jsonld.py", line 6402, in _is_numeric
    float(v)
TypeError: float() argument must be a string or a number, not 'datetime.date'
  1. Is this intended behavior? If yes, I probably could come up with a PR which would print a human understandable message instead of crash;
  2. If it is not, maybe date and datetime values should be natively supported by the library.