git » pymisc » master » tree

[master] / samples / contract / sample1.py

from contract import *


@contract
def f(a):
	"My beautiful function."

	@precond(f)
	def pre(a):
		"Precondition."
		print 'pre', a

	@postcond(f)
	def post(ret, a):
		"Postcondition."
		print 'post', ret, a

	print 'f', a
	return 2 * a


print '* run f'
r = f(26)
print '* f returned', r
print '* exit f'