AndreaCensi / contracts

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.
http://andreacensi.github.io/contracts/
Other
398 stars 62 forks source link

Likely bug that can't render contract violation #95

Closed Aceticia closed 2 years ago

Aceticia commented 3 years ago

I defined this custom contract:

new_contract('valid_communities', lambda s: communities.valid_communities(s))

And used it on an object's methods self argument like so:

@contract
    def find_pivot_comm_containing(
            self:'valid_communities', \
            idx_comm:'valid_community', \
            order:'None|str') -> 'None|list(tuple(int,int,valid_community))':

But when there is this error message when the 'valid_communities' contract is violated:

  File "/Users/xujinliu/anaconda/envs/GSP_dev/lib/python3.6/site-packages/contracts/library/extensions.py", line 121, in check_contract
    raise ContractNotRespected(self, msg, value, context)
contracts.interface.ContractNotRespected: <exception str() failed>

Any idea why this might be the case?