[Python-ideas] Pre-conditions and post-conditions

Stephan Houben stephanh42 at gmail.com
Wed Aug 29 01:58:39 EDT 2018


I
Op wo 29 aug. 2018 07:53 schreef Greg Ewing <greg.ewing at canterbury.ac.nz>:

> Wes Turner wrote:
> >     I'm going to re-write that in a pseudo-Eiffel like syntax:
>
> Maybe some magic could be done to make this work:
>
>       def __init__(self, img: np.ndarray, x: int, y: int, width: int,
>               height: int) -> None:
>
>           def __require__():
>               x >= 0
>               y >= 0
>               width >= 0
>               height >= 0
>               x + width <= pqry.opencv.width_of(img)
>               y + height <= pqry.opencv.height_of(img)
>
>           def __ensure__():
>               (self.x, self.y) in self
>               (self.x + self.width - 1, self.y + self.height - 1) in self
>               (self.x + self.width, self.y + self.height) not in self
>
>           # body of __init__ goes here...
>


I have often wished we could get at the AST of a function object.

Then we could inspect the AST and extract these magic functions.

Stephan

-- 
> Greg
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20180829/f48ba989/attachment-0001.html>


More information about the Python-ideas mailing list