RussBaz / enforce

Python 3.5+ runtime type checking for integration testing and data validation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Better error messages for some containers

kevinboulain opened this issue · comments

Hi there.

You seems to be quite reactive (#39) so I'll bother you with a nitpick as I was testing a couple of type-checking libraries the other day.

Here is the simple script:

from typing import Tuple, Dict
from enforce import runtime_validation

@runtime_validation
def example1(param: Tuple[int, int, int]) -> None:
    return None

@runtime_validation
def example2(param: Dict[str, int]) -> None:
    return None

example1((42, 42)) # Argument 'param' was not of type typing.Tuple[int, int, int]. Actual type was tuple.
example2({42: 42}) # Argument 'param' was not of type typing.Dict[str, int]. Actual type was typing.Dict[int, int].

As you can see with the comments, for example2/dict the error message is quite clear.
For example1/tuple the message lacks a bit of precision.

It could be nice to introspect the passed tuple here but it's not clear for me why nodes.TupleNode.validate_data uses input_type.__name__ as type_name instead of relying on something like get_actual_data_type.

I will investigate it. Thanks.

It should technically work, though. The exception message test for tuples is passing. It seems like another corner case is identified.

I pushed a patch to the dev. Please confirm if you are still experiencing this type of issues.

Well, I will close this issue for now as it seems fixed to me. Please open another issue if you find something else.