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
399 stars 61 forks source link

Docstring can't see local variables #45

Open averagehat opened 8 years ago

averagehat commented 8 years ago

Full tracebak here

In [13]: @contract
def fn(x):
        ''':type x: $SeqRecord'''
        return x.seq
.....
.....
raise RuntimeError("Cound not find a scope to lookup %s" % token)

ExternalScopedVariableNotFound: Token not found: 'SeqRecord'.

But it works fine outside of docstring:

In [13]: @contract(x='$SeqRecord')
def fn(x):
        return x.seq
In[14] # no error