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

:param: without accompanying :type: results in "AttributeError: 'NoneType' object has no attribute 'startswith'" #5

Closed geordanr closed 11 years ago

geordanr commented 12 years ago

The following script will produce an error:

#!/usr/bin/env python

from contracts import contract

@contract
def foo(bar, baz):
    '''
        :param bar: A thing.
        :type bar: str
        :param baz: Another thing.
    '''
    print bar, baz

if __name__ == '__main__':
    foo('hello', 'world')

The traceback is:

Traceback (most recent call last):
  File "foo.py", line 5, in <module>
    @contract
  File "/Users/geordan/src/contracts/src/contracts/main.py", line 166, in contract_decorator
    return contracts_decorate(function, **kwargs)
  File "/Users/geordan/src/contracts/src/contracts/main.py", line 228, in contracts_decorate
    accepts_dict, returns = parse_contracts_from_docstring(function)
  File "/Users/geordan/src/contracts/src/contracts/main.py", line 362, in parse_contracts_from_docstring
    for name in params])
  File "/Users/geordan/src/contracts/src/contracts/main.py", line 347, in remove_quotes
    if x.startswith('``') and x.endswith('``') and len(x) > 3:
AttributeError: 'NoneType' object has no attribute 'startswith'
AndreaCensi commented 12 years ago

Thanks for the report!

AndreaCensi commented 11 years ago

Fixed in last release.