PyContracts is a Python package that allows to declare constraints on function parameters and return values. Contracts can be specified using Python3 annotations, or inside a docstring. PyContracts supports a basic type system, variables binding, arithmetic constraints, and has several specialized contracts and an extension API.
It would be useful to have a contract for a function that require such an instance.
To keep python duck-typing semantic, we can check the instance members (just like we do for dict), but checking one by one :
It would be helpful to check custom types.
For example if an instance of a class is defined as such :
It would be useful to have a contract for a function that require such an instance. To keep python duck-typing semantic, we can check the instance members (just like we do for dict), but checking one by one :
This way any object that has an int
class_member
and an intinst_member
will satisfy the contract.I am posting this issue because I haven't found any way to do this currently...