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

cannot specify parameter type as file in docstring #36

Closed gezakiss7 closed 9 years ago

gezakiss7 commented 9 years ago

Is there a way to specify that a parameter's type is file in the docstring? The expression ":type in_file: file" does not work, nor do other formats I could think of. (Note that the decorator "@contract(in_file=file)" works, but I'd like to use the docstring.)

textbook commented 9 years ago

It's only a workaround, but note that

:type in_file: isinstance(file)

will work correctly (i.e. you won't get e.g. ParseSyntaxException: Unknown identifier 'file'. Did you mean 'finite'? and non-file arguments will be rejected).