cascading python executions only if return code is 0
roy at panix.com
Mon Dec 23 20:03:37 CET 2013
On Monday, December 23, 2013 12:05:22 PM UTC-5, Steven D'Aprano wrote:
> Roy Smith wrote:
> > And, yes, I know that assertions get turned off with -O (frankly, I
> > think that's a design flaw). We don't run with -O.
> Until such time as somebody decides they can speed up your code by 5% by
> running with optimizations turned on.
Well, there's lots of changes people could make that would break things. Many of them are in the name of efficiency.  But, let's say they did that. We would fall off the end of the function, return None, and the caller would end up doing:
leaving somebody to puzzle over why the logs contained a stack dump ending in:
So, here's the deeper question. Is your issue strictly that -O elides assert statements?  That's a purely mechanical issue that could be solved by using the rather more verbose:
if not condition:
Would you feel differently then?
> So there's always tension between "why am I testing something that can't
> fail?" and "but what if it does?"
Trust, but verify. Especially when the thing you're verifying is your understanding of how your own code works :-)
 and most of those are premature optimizations. To a first order approximation, for us, application speed is all about database performance, and not at all about Python code execution speed. That's a pretty good second order approximation as well.
 In which case, we would just add some middleware which did:
assert "-O" not in sys.argv
More information about the Python-list