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

String contracts don't accept ! (not) #68

Open jcrmatos opened 6 years ago

jcrmatos commented 6 years ago

Hello,

If I try using this

@contract(txt_pn='str, != ""', returns='list(str, != ""')
def load_txt2lst(txt_pn):
    # type: (str) -> List[str]
    ...

or this

@contract(txt_pn='str, != \'\'', returns='list(str, != \'\'')
def load_txt2lst(txt_pn):
    # type: (str) -> List[str]
    ...

this error is returned

...
    return parse_contract_string_actual(string)
  File "C:\Users\JMatos\Envs\solve_sudoku\lib\site-packages\contracts\main_actua
l.py", line 41, in parse_contract_string_actual
    raise ContractSyntaxError(msg, where=where)
contracts.interface.ContractSyntaxError: Expected operation with ["!"] (at char
13), (line:1, col:14)

 line  1 |list(str, != ""
                       \u2191

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "solve_sudoku.py", line 58, in <module>
    @contract(txt_pn='str, != ""', returns='list(str, != ""')
  File "C:\Users\JMatos\Envs\solve_sudoku\lib\site-packages\contracts\main.py",
line 149, in tmp_wrap
    raise e.copy()
contracts.interface.ContractSyntaxError: Expected operation with ["!"] (at char
13), (line:1, col:14)

 line  1 |list(str, != ""
                       \u2191

I am doing something wrong or is it a bug?

I'm using Python 3.5.4 32b and pycontracts 1.8.3 under Windows 7 Pro x64.

Thanks,

JM