Contracts for Python

P

Paulo J. Matos

Hi all,

I am wondering if there is any work on contracts for Python. I could
only find PEP316, however, I am wondering if there is any official
support for it already (tools I mean), and if it is or if it will be
officially supported in any of the next releases of Python.

Cheers,
 
A

alex23

I am wondering if there is any work on contracts for Python. I could
only find PEP316, however, I am wondering if there is any official
support for it already (tools I mean), and if it is or if it will be
officially supported in any of the next releases of Python.

It's possible to get a simplistic design-by-contract approach without
external libs by using 'assert'.

Here's a modified example from PEP 316:

class circbuf:

def __init__(self, leng):
"""Construct an empty circular buffer."""

# pre
assert leng > 0, "pre: length not positive"

...

# post
assert self.is_empty(), "post: buffer not empty"
assert len(self.buf) == leng, "post: buffer length incorrect"
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,141
Latest member
BlissKeto
Top