Skip to content

unhandled exception in check_contract #89

@HitLuca

Description

@HitLuca

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions