Contracts for Python

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Paulo J. Matos

    Contracts for Python

    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,
    --
    Paulo Jorge Matos - pocmatos at gmail.com
    Webpage: http://www.personal.soton.ac.uk/pocm
  • alex23

    #2
    Re: Contracts for Python

    On Oct 29, 3:47 am, "Paulo J. Matos" <pocma...@gmail .comwrote:
    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):
    """Construc t 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"

    Comment

    Working...