Design By Contract in Python

Ryan Freckleton ryan_p1 at cerris.com
Tue Nov 18 01:22:36 EST 2008


Hi Everyone,

I'm currently developing a decorator and metaclass based implementation 
of design by contract for python. (I'd have uploaded it to PyPI already, 
but I haven't had time to create a GPG key) and wanted to see if anyone 
wanted to take a look or interested in trying it out.

Basically design by contract is a way of verifying expectations about 
object state and method use at runtime. There are a few python packages 
that already exist and attempt to do this, but they have some problems 
with implementation (they would fail on the example given below) or API 
(they put expectations in docstrings) that I don't agree with.

I haven't tried this out with diamond (or multiple) inheritance, and 
there are still a few features missing. But it should be pretty rock 
solid besides those points.

Any and all constructive critiques are be welcome

Implementation:    http://pastebin.com/f368d5396
Example class:      http://pastebin.com/f51be54be


Thanks,
Ryan Freckleton




More information about the Python-list mailing list