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

2018-08-27 Thread Marko Ristin-Kaufmann
Hi, To clarify the benefits of the contracts, let me give you an example from our code base: @icontract.pre(lambda x: x >= 0) @icontract.pre(lambda y: y >= 0) @icontract.pre(lambda width: width >= 0) @icontract.pre(lambda height: height >= 0) @icontract.pre(lambda x, width, img: x + width <=

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

2018-08-27 Thread Wes Turner
Thanks for the explanation. This may be a bit OT, but is there a good way to do runtime assertions (in particular for data validation) that's as easy as assert? - self.assertEqual (unittest.TestCase.assertEqual) is hardly usable in other class instances, - pytest can be used at runtime but has

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

2018-08-27 Thread Steven D'Aprano
On Mon, Aug 27, 2018 at 11:01:21AM -0400, Wes Turner wrote: > Runtime checks: data validation & code validation > Compile-time checks: code validation > > What sort of data validation is appropriate for assert statements or > contacts that may be skipped due to trading performance for more risk >

Re: [Python-ideas] Python-ideas Digest, Vol 141, Issue 145

2018-08-27 Thread James Lu
;", line 1, in > > AttributeError: type object 'tuple' has no attribute '__iadd__' > > type object 'tuple' has no attribute '__iadd__' > > >>> tuple.__add__ > > > > >>> list.__iadd__ > > > > >>> list.__add__ &g

Re: [Python-ideas] A GUI for beginners and experts alike

2018-08-27 Thread Brett Cannon
On Fri, 24 Aug 2018 at 18:18 Mike Barnett wrote: > It’s fascinating just how many packages are being dragged out for > examination or clobbering other than the one that I asked for > assistance/help on. > > > > I see the code of conduct link in the thread. Perhaps a review would be > helpful. >

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

2018-08-27 Thread Wes Turner
Runtime checks: data validation & code validation Compile-time checks: code validation What sort of data validation is appropriate for assert statements or contacts that may be skipped due to trading performance for more risk ('optimized out')? Checking the value of a Number? Checking that a

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

2018-08-27 Thread Steven D'Aprano
On Mon, Aug 27, 2018 at 11:00:22PM +1000, Chris Angelico wrote: > Sometimes "type" doesn't mean the same thing to the language and to > the human. Suppose you're trying to create a Python script that > replicates a C program; you might want to declare that a variable is > not of type "integer"

[Python-ideas] PEP 420: implicit namespace sub-package

2018-08-27 Thread Gallian Colombeau
Hello, the PEP 420 (Implicit Namespace Packages) is quite descriptive about the problem and the solution implemented back in Python 3.3 but I feel there may be a part missing (but maybe this is categorized as an implementation detail). As I understand, for a package to allow being extended

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

2018-08-27 Thread Chris Angelico
On Mon, Aug 27, 2018 at 10:50 PM, Steven D'Aprano wrote: > On Mon, Aug 27, 2018 at 12:12:22PM +0100, Ivan Levkivskyi wrote: >> Contract in 99% of cases is just another word for type (maybe a very >> complex type like `DAG[T] <: Graph[T]`). >> Everything else, like `x >= y` is better expressed as

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

2018-08-27 Thread Steven D'Aprano
On Mon, Aug 27, 2018 at 12:12:22PM +0100, Ivan Levkivskyi wrote: > On Mon, 27 Aug 2018 at 11:39, Steven D'Aprano wrote: > > > On Mon, Aug 27, 2018 at 09:24:20AM +0100, Ivan Levkivskyi wrote: > > > TBH, I think one of the main points of design by contract is that > > contracts > > > are verified

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

2018-08-27 Thread Jonathan Fine
Ivan and Steve wrote >> TBH, I think one of the main points of design by contract is that contracts >> are verified statically. > No, that's not correct. > https://www.eiffel.org/doc/eiffel/ET-_Design_by_Contract_%28tm%29%2C_Assertions_and_Exceptions The page from Steve supplied (URL above)

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

2018-08-27 Thread Ivan Levkivskyi
On Mon, 27 Aug 2018 at 11:39, Steven D'Aprano wrote: > On Mon, Aug 27, 2018 at 09:24:20AM +0100, Ivan Levkivskyi wrote: > > TBH, I think one of the main points of design by contract is that > contracts > > are verified statically. > > No, that's not correct. Contracts may be verified statically

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

2018-08-27 Thread Steven D'Aprano
On Mon, Aug 27, 2018 at 09:24:20AM +0100, Ivan Levkivskyi wrote: > TBH, I think one of the main points of design by contract is that contracts > are verified statically. No, that's not correct. Contracts may be verified statically if the compiler is able to do so, but they are considered runtime

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

2018-08-27 Thread Steven D'Aprano
On Mon, Aug 27, 2018 at 09:04:21AM +0200, Jacco van Dorp wrote: > Total noob speaking here, but > > Those contracts are mostly important during development right ? That assumes that production code is free of bugs. Usual practice in the Eiffel world is, I believe, to disable post-

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

2018-08-27 Thread Ivan Levkivskyi
TBH, I think one of the main points of design by contract is that contracts are verified statically. For runtime contract checking I would rather recommend hypothesis library (or similar). -- Ivan On Mon, 27 Aug 2018 at 08:05, Jacco van Dorp wrote: > Total noob speaking here, but > >

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

2018-08-27 Thread Jacco van Dorp
Total noob speaking here, but Those contracts are mostly important during development right ? Slowdown isn't that much of an issue during development. So you could make a debug mode that enforces the contracts, and a production mode that code users can use during production to stop the

Re: [Python-ideas] Unpacking iterables for augmented assignment

2018-08-27 Thread Jonathan Fine
James has suggested that Python be enhanced so that >>> a, b += c, d is a short-hand for >>> a += c >>> b += d Myself, James and Matthew wrote >> > Does it IN PRACTICE bring sufficient benefits to users? >> I found myself needing this when I was writing a monte-carlo >> simulation in python