contracts icon indicating copy to clipboard operation
contracts copied to clipboard

unhandled exception in check_contract

Open HitLuca opened this issue 6 years ago • 0 comments

when trying to add a @contract decorator to a function that has parametrized tuples as hints (e.g. Tuple[int, float]), breaks contracts with the error TypeError: Parameterized Tuple cannot be used with isinstance().

The first thing would be to return a better error instead of that obscure one, like "cannot add contracts to a function that has parametrized tuples as type hints" or similar.

Second, this issue may be fixed by adding a check in check_contract of CheckType for the values of self.types: if a parametrized tuple is used in the comparison, the value of self.types.__args__ will be a tuple of types composing it ('__args__': (<class 'int'>, <class 'float'>). Knowing that one could loop through every input element in the tuple and compare its type with the expected one

HitLuca avatar Mar 06 '20 16:03 HitLuca