mitsuse / typedjson-python

JSON decoding for Python with type hinting (PEP 484).
MIT License
29 stars 5 forks source link

`decode()` does not save `result.path` variable. #5

Closed ghost closed 5 years ago

ghost commented 5 years ago

@mitsuse, the decode function (from typedjson/decoding.py) does not save the result.path variable when result is an instance of DecodingError. I don't think this is intended since this produces the following issue. Consider for example this call:

print(typedjson.decode(Tuple[int,int], (1,'2')))

Right now this produces DecodingError(()) while I suppose it should produce DecodingError(('1',)). I think that we should check if the result.path variable was changed and in that case update the path parameter like so:

for d in decoders:
   result = d(type_, json, path)
   if not isinstance(result, DecodingError):
      break
   elif result.path:
      path = result.path
mitsuse commented 5 years ago

@rruc Yes, this is a bug. We cannot known which decoder should be applied previously on the current implementation, so DecodingError should be divided into two types: errors for validation and unsuitable decoder.

mitsuse commented 5 years ago

@rruc Thanks for filing this bug! The bug is fixed in 7fa153d.