<div dir="auto"><div>Hi Mario, </div><div dir="auto">yes I'd pass in some kind of 'old' object as a proxy to the old object state. </div><div dir="auto"><br></div><div dir="auto">My demo can handle function calls, unless they themselves ultimately call something which can't be proxies e.g is instance (which delegates to the test class, not the instance), or boolean evaluation of some expression (e.g an if block). I don't think that this is awful - contracts should probably be fairly concise while expressive - but definitely non-ideal. </div><div dir="auto"> </div><div dir="auto">I haven't really time to work on this at the moment; I admit, it was a specific problem of interest, rather than a domain I have much experience with. In fact, it was probably an excuse to overload all of the operators on an object! </div><div dir="auto"><br></div><div dir="auto">Kind regards, </div><div dir="auto">Angus <br><br><div class="gmail_quote" dir="auto"><div dir="ltr">On Mon, 24 Sep 2018, 20:09 Marko Ristin-Kaufmann, <<a href="mailto:marko.ristin@gmail.com" target="_blank" rel="noreferrer">marko.ristin@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto">Hi Barry,<div dir="auto">I think the main issue with pyffel is that it can not support function calls in general. If I understood it right, and Angus please correct me, you would need to wrap every function that you would call from within the contract.</div><div dir="auto"><br></div><div dir="auto">But the syntax is much nicer than icontract or dpcontracts (see these packages on pypi). What if we renamed "args" argument and "old" argument in those libraries to just "a" and "o", respectively? Maybe that gives readable code without too much noise:</div><div dir="auto"><br></div><div dir="auto">@requires(lambda self, a, o: self.sum == o.sum - a.amount)</div><div dir="auto">def withdraw(amount: int) -> None:</div><div dir="auto">    ...</div><div dir="auto"><br></div><div dir="auto">There is this lambda keyword in front, but it's not too bad?</div><div dir="auto"><br></div><div dir="auto">I'll try to contact dpcontracts maintainers. Maybe it's possible to at least merge a couple of libraries into one and make it a de facto standard. @Agnus, would you also like to join the effort?</div><div dir="auto"><br></div><div dir="auto">Cheers,</div><div dir="auto">Marko</div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><br></div><div dir="auto"><br></div></div><br><div class="gmail_quote"><div dir="ltr">Le lun. 24 sept. 2018 à 19:57, Barry Scott <<a href="mailto:barry@barrys-emacs.org" rel="noreferrer noreferrer" target="_blank">barry@barrys-emacs.org</a>> a écrit :<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word;line-break:after-white-space"><br><div><br><blockquote type="cite"><div>On 23 Sep 2018, at 11:13, Angus Hollands <<a href="mailto:goosey15@gmail.com" rel="noreferrer noreferrer noreferrer" target="_blank">goosey15@gmail.com</a>> wrote:</div><br class="m_759978510890961797m_-5595370882790786662m_-8577334642648634674Apple-interchange-newline"><div><div dir="ltr"><div class="m_759978510890961797m_-5595370882790786662m_-8577334642648634674markdown-here-wrapper"><p style="margin:0px 0px 1.2em!important">Hi Marko,</p><p style="margin:0px 0px 1.2em!important">I think there are several ways to approach this problem, though am not weighing in on whether DbC is a good thing in Python. I wrote a simple implementation of DbC which is currently a run-time checker. You could, with the appropriate tooling, validate statically too (as with all approaches). In my approach, I use a “proxy” object to allow the contract code to be defined at function definition time. It does mean that some things are not as pretty as one would like - anything that cannot be hooked into with magic methods i.e <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">isinstance</code>, but I think this is acceptable as it makes features like <code style="font-size:0.85em;font-family:Consolas,Inconsolata,Courier,monospace;margin:0px 0.15em;padding:0px 0.3em;white-space:pre-wrap;border:1px solid rgb(234,234,234);background-color:rgb(248,248,248);border-radius:3px;display:inline">old</code> easier. Also, one hopes that it encourages simpler contract checks as a side-effect. Feel free to take a look - <a href="https://github.com/agoose77/pyffel" rel="noreferrer noreferrer noreferrer" target="_blank">https://github.com/agoose77/pyffel</a><br>It is by no means well written, but a fun PoC nonetheless.<br></p></div></div></div></blockquote><div>This is an interesting PoC, nice work! I like that its easy to read the tests.</div><div><br></div><div>Given a library like this the need to build DbC into python seems unnecessary.</div><div><br></div><div>What do other people think?</div><div><br></div><div>Barry</div><div><br></div><div><br></div><br><blockquote type="cite"><div><div dir="ltr"><div class="m_759978510890961797m_-5595370882790786662m_-8577334642648634674markdown-here-wrapper"><p style="margin:0px 0px 1.2em!important">Regards,<br>Angus</p>
<div title="MDH:SGkgTWFya28sPGRpdj48YnI+PC9kaXY+PGRpdj5JIHRoaW5rIHRoZXJlIGFyZSBzZXZlcmFsIHdh
eXMgdG8gYXBwcm9hY2ggdGhpcyBwcm9ibGVtLCB0aG91Z2ggYW0gbm90IHdlaWdoaW5nIGluIG9u
IHdoZXRoZXIgRGJDIGlzIGEgZ29vZCB0aGluZyBpbiBQeXRob24uIEkgd3JvdGUgYSBzaW1wbGUg
aW1wbGVtZW50YXRpb24gb2YgRGJDIHdoaWNoIGlzIGN1cnJlbnRseSBhIHJ1bi10aW1lIGNoZWNr
ZXIuIFlvdSBjb3VsZCwgd2l0aCB0aGUgYXBwcm9wcmlhdGUgdG9vbGluZywgdmFsaWRhdGUgc3Rh
dGljYWxseSB0b28gKGFzIHdpdGggYWxsIGFwcHJvYWNoZXMpLiBJbiBteSBhcHByb2FjaCwgSSB1
c2UgYSAicHJveHkiIG9iamVjdCB0byBhbGxvdyB0aGUgY29udHJhY3QgY29kZSB0byBiZSBkZWZp
bmVkIGF0IGZ1bmN0aW9uIGRlZmluaXRpb24gdGltZS4gSXQgZG9lcyBtZWFuIHRoYXQgc29tZSB0
aGluZ3MgYXJlIG5vdCBhcyBwcmV0dHkgYXMgb25lIHdvdWxkIGxpa2UgLSBhbnl0aGluZyB0aGF0
IGNhbm5vdCBiZSBob29rZWQgaW50byB3aXRoIG1hZ2ljIG1ldGhvZHMgaS5lIGBpc2luc3RhbmNl
YCwgYnV0IEkgdGhpbmsgdGhpcyBpcyBhY2NlcHRhYmxlIGFzIGl0IG1ha2VzIGZlYXR1cmVzIGxp
a2UgYG9sZGAgZWFzaWVyLiBBbHNvLCBvbmUgaG9wZXMgdGhhdCBpdCBlbmNvdXJhZ2VzIHNpbXBs
ZXIgY29udHJhY3QgY2hlY2tzIGFzIGEgc2lkZS1lZmZlY3QuIEZlZWwgZnJlZSB0byB0YWtlIGEg
bG9vayAtIDxhIGhyZWY9Imh0dHBzOi8vZ2l0aHViLmNvbS9hZ29vc2U3Ny9weWZmZWwiPmh0dHBz
Oi8vZ2l0aHViLmNvbS9hZ29vc2U3Ny9weWZmZWw8L2E+Jm5ic3A7PGJyPkl0IGlzIGJ5IG5vIG1l
YW5zIHdlbGwgd3JpdHRlbiwgYnV0IGEgZnVuIFBvQyBub25ldGhlbGVzcy48YnI+UmVnYXJkcyw8
L2Rpdj48ZGl2PkFuZ3VzPC9kaXY+" style="height:0;width:0;max-height:0;max-width:0;overflow:hidden;font-size:0em;padding:0;margin:0">​</div></div></div>
_______________________________________________<br>Python-ideas mailing list<br><a href="mailto:Python-ideas@python.org" rel="noreferrer noreferrer noreferrer" target="_blank">Python-ideas@python.org</a><br><a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer noreferrer noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer noreferrer noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br></div></blockquote></div><br></div>_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org" rel="noreferrer noreferrer noreferrer" target="_blank">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" rel="noreferrer noreferrer noreferrer noreferrer" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</blockquote></div>
</blockquote></div></div></div>