Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
lightweight contracts for python
Python
Tree: 83097d6846

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
.gitignore
README.md
TODO
contract.py
tests.py

README.md

Simple, type-of-value based contracts for Python, as decorators.

For example, here's a method that takes a string, and returns a string.

@contract(str, str)
def exclaim(s):
    return s + '!'

exclaim('hello') # prints 'hello!'
exclaim(5)       # raises FailedContract

Here's a method that takes a string, and returns a method that takes a string and returns a string.

@contract(str, contract(str, str))
def prepender(s):
    @contract('(str,) -> str')
    def wrapper(s2):
        return s + s2
    return wrapper

prepender('hello, ')('dave') # prints 'hello, dave'
prepender(5)                 # raises FailedContract
prepender('hi')(5)           # raises FailedContract
Something went wrong with that request. Please try again.