RussBaz / enforce

Python 3.5+ runtime type checking for integration testing and data validation
543 stars 21 forks source link

list index out of range when validating list in list #31

Closed magwas closed 7 years ago

magwas commented 7 years ago

test.py:

from typing import Union, List
from enforce.decorators import runtime_validation

I18ableMessage = List[str]
I18ableMessages = Union[str,List[I18ableMessage]]

@runtime_validation
def test(msg: I18ableMessages):
    print(msg)

test([["a","b"],["x","y"]])

python3 test.py

Traceback (most recent call last):
  File "test.py", line 11, in <module>
    test([["a","b"],["x","y"]])
  File "/usr/local/lib/python3.5/dist-packages/enforce/decorators.py", line 109, in universal
    _args, _kwargs, _ = enforcer.validate_inputs(parameters)
  File "/usr/local/lib/python3.5/dist-packages/enforce/enforcers.py", line 77, in validate_inputs
    if not self.validator.validate(argument, name):
  File "/usr/local/lib/python3.5/dist-packages/enforce/validator.py", line 26, in validate
    result = visit(validation_tree)
  File "/usr/local/lib/python3.5/dist-packages/enforce/utils.py", line 17, in visit
    stack.append(last.send(last_result))
  File "/usr/local/lib/python3.5/dist-packages/enforce/nodes.py", line 84, in validate_children
    result = yield child.validate(propagated_data[i], validator, self.type_var)
IndexError: list index out of range
RussBaz commented 7 years ago

Thanks for the report. It is interesting bug. I found what happens but not yet what causes such a behaviour in this case only. I will keep you updated.

RussBaz commented 7 years ago

OK, I think I fixed it. It is now in the dev branch. It will be available with the next release. You can try the dev version for now.

Thanks for waiting.