Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #62541 > unrolled thread
| Started by | Frank Cui <ycui@outlook.com> |
|---|---|
| First post | 2013-12-22 15:37 -0300 |
| Last post | 2013-12-23 15:22 +0000 |
| Articles | 7 on this page of 67 — 18 participants |
Back to article view | Back to comp.lang.python
cascading python executions only if return code is 0 Frank Cui <ycui@outlook.com> - 2013-12-22 15:37 -0300
Re: cascading python executions only if return code is 0 Roy Smith <roy@panix.com> - 2013-12-22 14:17 -0500
Re: cascading python executions only if return code is 0 Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-22 19:31 +0000
Re: cascading python executions only if return code is 0 Roy Smith <roy@panix.com> - 2013-12-22 15:05 -0500
Re: cascading python executions only if return code is 0 Cameron Simpson <cs@zip.com.au> - 2013-12-23 08:39 +1100
Re: cascading python executions only if return code is 0 Roy Smith <roy@panix.com> - 2013-12-22 16:53 -0500
Re: cascading python executions only if return code is 0 Cameron Simpson <cs@zip.com.au> - 2013-12-23 09:11 +1100
Re: cascading python executions only if return code is 0 Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-12-22 22:10 -0500
Re: cascading python executions only if return code is 0 Chris Angelico <rosuav@gmail.com> - 2013-12-23 14:22 +1100
Re: cascading python executions only if return code is 0 Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-23 03:43 +0000
Re: cascading python executions only if return code is 0 Chris Angelico <rosuav@gmail.com> - 2013-12-23 14:45 +1100
Re: cascading python executions only if return code is 0 Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-23 03:54 +0000
Re: cascading python executions only if return code is 0 Chris Angelico <rosuav@gmail.com> - 2013-12-23 14:59 +1100
RE: cascading python executions only if return code is 0 Frank Cui <ycui@outlook.com> - 2013-12-22 16:10 -0300
Re: cascading python executions only if return code is 0 Ned Batchelder <ned@nedbatchelder.com> - 2013-12-22 14:49 -0500
Re: cascading python executions only if return code is 0 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-23 00:08 +0000
RE: cascading python executions only if return code is 0 Frank Cui <ycui@outlook.com> - 2013-12-22 16:35 -0300
Re: cascading python executions only if return code is 0 Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2013-12-23 13:30 +1300
Re: cascading python executions only if return code is 0 Rick Johnson <rantingrickjohnson@gmail.com> - 2013-12-22 14:27 -0800
RE: cascading python executions only if return code is 0 Frank Cui <ycui@outlook.com> - 2013-12-22 19:14 -0300
Re: cascading python executions only if return code is 0 Chris Angelico <rosuav@gmail.com> - 2013-12-23 09:51 +1100
Re: cascading python executions only if return code is 0 Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-22 23:02 +0000
Re: cascading python executions only if return code is 0 Rick Johnson <rantingrickjohnson@gmail.com> - 2013-12-22 15:57 -0800
Re: cascading python executions only if return code is 0 Ned Batchelder <ned@nedbatchelder.com> - 2013-12-23 07:27 -0500
Re: cascading python executions only if return code is 0 Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-23 12:44 +0000
Re: cascading python executions only if return code is 0 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-23 00:25 +0000
Re: cascading python executions only if return code is 0 Roy Smith <roy@panix.com> - 2013-12-22 20:24 -0500
Re: cascading python executions only if return code is 0 Chris Angelico <rosuav@gmail.com> - 2013-12-23 12:35 +1100
Re: cascading python executions only if return code is 0 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-23 13:33 +1100
Re: cascading python executions only if return code is 0 Chris Angelico <rosuav@gmail.com> - 2013-12-23 14:09 +1100
Re: cascading python executions only if return code is 0 Roy Smith <roy@panix.com> - 2013-12-22 23:57 -0500
Re: cascading python executions only if return code is 0 Chris Angelico <rosuav@gmail.com> - 2013-12-23 16:09 +1100
Re: cascading python executions only if return code is 0 Ethan Furman <ethan@stoneleaf.us> - 2013-12-23 04:45 -0800
Re: cascading python executions only if return code is 0 Roy Smith <roy@panix.com> - 2013-12-23 10:10 -0500
Re: cascading python executions only if return code is 0 Ethan Furman <ethan@stoneleaf.us> - 2013-12-23 08:00 -0800
Re: cascading python executions only if return code is 0 Roy Smith <roy@panix.com> - 2013-12-26 20:37 -0500
Re: cascading python executions only if return code is 0 Chris Angelico <rosuav@gmail.com> - 2013-12-27 12:44 +1100
Re: cascading python executions only if return code is 0 Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-12-26 21:20 -0500
Re: cascading python executions only if return code is 0 Chris Angelico <rosuav@gmail.com> - 2013-12-27 13:27 +1100
Re: cascading python executions only if return code is 0 Roy Smith <roy@panix.com> - 2013-12-26 23:29 -0500
Re: cascading python executions only if return code is 0 Chris Angelico <rosuav@gmail.com> - 2013-12-27 15:40 +1100
Re: cascading python executions only if return code is 0 Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-12-27 11:15 -0500
Re: cascading python executions only if return code is 0 Roy Smith <roy@panix.com> - 2013-12-27 11:42 -0500
Re: cascading python executions only if return code is 0 Rustom Mody <rustompmody@gmail.com> - 2013-12-27 22:39 +0530
Re: cascading python executions only if return code is 0 Chris Angelico <rosuav@gmail.com> - 2013-12-28 08:24 +1100
Re: cascading python executions only if return code is 0 pecore@pascolo.net - 2013-12-28 00:59 +0100
Re: cascading python executions only if return code is 0 Gene Heskett <gheskett@wdtv.com> - 2013-12-27 19:12 -0500
Re: cascading python executions only if return code is 0 Tim Chase <python.list@tim.thechases.com> - 2013-12-26 20:50 -0600
Re: cascading python executions only if return code is 0 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-27 15:39 +1100
Re: cascading python executions only if return code is 0 Chris Angelico <rosuav@gmail.com> - 2013-12-27 15:45 +1100
Re: cascading python executions only if return code is 0 Roy Smith <roy@panix.com> - 2013-12-27 00:05 -0500
Re: cascading python executions only if return code is 0 Chris Angelico <rosuav@gmail.com> - 2013-12-27 16:15 +1100
Re: cascading python executions only if return code is 0 Roy Smith <roy@panix.com> - 2013-12-27 00:41 -0500
Re: cascading python executions only if return code is 0 Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-27 18:00 +0000
Re: cascading python executions only if return code is 0 Grant Edwards <invalid@invalid.invalid> - 2013-12-30 17:36 +0000
Re: cascading python executions only if return code is 0 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-24 04:05 +1100
Re: cascading python executions only if return code is 0 Roy Smith <roy@panix.com> - 2013-12-23 11:03 -0800
Re: cascading python executions only if return code is 0 Chris Angelico <rosuav@gmail.com> - 2013-12-24 06:12 +1100
RE: cascading python executions only if return code is 0 Nick Cash <nick.cash@npcinternational.com> - 2013-12-23 19:31 +0000
Re: cascading python executions only if return code is 0 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-24 14:41 +1100
Re: cascading python executions only if return code is 0 Roy Smith <roy@panix.com> - 2013-12-23 22:58 -0500
Re: cascading python executions only if return code is 0 Peter Otten <__peter__@web.de> - 2013-12-23 18:45 +0100
Re: cascading python executions only if return code is 0 Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-23 13:20 +0000
Re: cascading python executions only if return code is 0 Ethan Furman <ethan@stoneleaf.us> - 2013-12-23 04:38 -0800
Re: cascading python executions only if return code is 0 Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2013-12-23 10:12 -0500
Re: cascading python executions only if return code is 0 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-12-24 04:13 +1100
Re: cascading python executions only if return code is 0 Mark Lawrence <breamoreboy@yahoo.co.uk> - 2013-12-23 15:22 +0000
Page 4 of 4 — ← Prev page 1 2 3 [4]
| From | Roy Smith <roy@panix.com> |
|---|---|
| Date | 2013-12-23 22:58 -0500 |
| Message-ID | <roy-591B88.22585923122013@news.panix.com> |
| In reply to | #62665 |
In article <52b90263$0$30003$c3e8da3$5496439d@news.astraweb.com>,
Steven D'Aprano <steve+comp.lang.python@pearwood.info> wrote:
> Roy Smith wrote:
>
> > 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:
> > raise AssertionError("....")
> >
> > Would you feel differently then?
>
>
> Not quite. As I said in my initial rant, there's also the issue of using an
> appropriate exception.
> [...]
> If I think that the test is checking an internal invariant, assert is okay,
> if not, it isn't.
Well, in this case, that's what it's doing, so I guess I'm good :-)
[toc] | [prev] | [next] | [standalone]
| From | Peter Otten <__peter__@web.de> |
|---|---|
| Date | 2013-12-23 18:45 +0100 |
| Message-ID | <mailman.4568.1387820727.18130.python-list@python.org> |
| In reply to | #62631 |
Ethan Furman wrote:
>> Sigh. Sometimes I'm not sure which is worse. The anti-assertion
>> zealotry on this list, or the anti-regex zealotry.
>
> I am not a zealot (I'm not! Really!! ;) . I just find it alarming to
> have major pieces of software rely on a feature that can be so easily
> tuned out, and it wasn't clear from your comment that it was /any/
> exception.
>
> Mostly I don't want newbies thinking "Hey! I can use assertions for all
> my confidence testing!"
>
> Just as one data point OpenERP, which has a lot of good features,
> unfortunately uses assert to test user input. :(
Put the following at the beginning of every affected module:
try:
assert 0
except AssertionError:
pass
else:
raise AssertionError("won't run with assertions turned off")
:)
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2013-12-23 13:20 +0000 |
| Message-ID | <mailman.4554.1387804844.18130.python-list@python.org> |
| In reply to | #62592 |
On 23/12/2013 12:45, Ethan Furman wrote: > > Considering how easy it is to disable assertions, a circle in the sand > is an amazingly appropriate metaphor. :) > > -- > ~Ethan~ It might be easy, but surely it's far more fun providing an itertools solution :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence
[toc] | [prev] | [next] | [standalone]
| From | Ethan Furman <ethan@stoneleaf.us> |
|---|---|
| Date | 2013-12-23 04:38 -0800 |
| Message-ID | <mailman.4555.1387805190.18130.python-list@python.org> |
| In reply to | #62577 |
On 12/22/2013 06:33 PM, Steven D'Aprano wrote: > Roy Smith wrote: >> >> else: >> assert 0, "can't create picker (classes = %s)" % classes > > ¡Ay, caramba! I was with you until the very last line. The above code is > possibly buggy and inappropriately designed. [...] > > First, the bug: there are circumstances where no exception is raised even if > all the strategies fail. Since Steven wasn't explicit about the circumstances, I'll list the two I'm aware of: if Python is started with -O or -OO then assertions are cut from the code and do not run: ethan@media:~/source/python/issue19995$ ./python -O Python 3.4.0b1 (default:be22ffb4fdf1, Dec 20 2013, 12:26:10) [GCC 4.7.3] on linux Type "help", "copyright", "credits" or "license" for more information. --> assert 0, "Testing" --> # no exception raised
[toc] | [prev] | [next] | [standalone]
| From | Dennis Lee Bieber <wlfraed@ix.netcom.com> |
|---|---|
| Date | 2013-12-23 10:12 -0500 |
| Message-ID | <mailman.4559.1387811582.18130.python-list@python.org> |
| In reply to | #62577 |
On Mon, 23 Dec 2013 13:33:08 +1100, Steven D'Aprano
<steve+comp.lang.python@pearwood.info> declaimed the following:
>Roy Smith wrote:
>
>
>> else:
>> assert 0, "can't create picker (classes = %s)" % classes
>
>¡Ay, caramba! I was with you until the very last line. The above code is
>possibly buggy and inappropriately designed. (I may be completely
>misinterpreting this, in which case feel free to ignore the following
>rant.)
>
I'd think the biggest problem with this is that if one runs Python with
optimization turned on, the assert statement itself vanishes, leaving one
with an empty else clause...
Try debugging that problem!
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed@ix.netcom.com HTTP://wlfraed.home.netcom.com/
[toc] | [prev] | [next] | [standalone]
| From | Steven D'Aprano <steve+comp.lang.python@pearwood.info> |
|---|---|
| Date | 2013-12-24 04:13 +1100 |
| Message-ID | <52b86f30$0$29975$c3e8da3$5496439d@news.astraweb.com> |
| In reply to | #62632 |
Dennis Lee Bieber wrote:
> On Mon, 23 Dec 2013 13:33:08 +1100, Steven D'Aprano
> <steve+comp.lang.python@pearwood.info> declaimed the following:
>
>>Roy Smith wrote:
>>
>>
>>> else:
>>> assert 0, "can't create picker (classes = %s)" % classes
>>
>>¡Ay, caramba! I was with you until the very last line. The above code is
>>possibly buggy and inappropriately designed. (I may be completely
>>misinterpreting this, in which case feel free to ignore the following
>>rant.)
>>
>
> I'd think the biggest problem with this is that if one runs Python with
> optimization turned on, the assert statement itself vanishes, leaving one
> with an empty else clause...
>
> Try debugging that problem!
Actually, that's not correct. If the assert statement vanishes, so does the
else clause, since there's nothing in it.
[steve@ando ~]$ python2.7 -c "from dis import dis
> code = compile('''\
> for x in [1, 2, 3]:
> pass
> else:
> assert x
> ''', '', 'exec')
> dis(code)"""
1 0 SETUP_LOOP 35 (to 38)
3 LOAD_CONST 0 (1)
6 LOAD_CONST 1 (2)
9 LOAD_CONST 2 (3)
12 BUILD_LIST 3
15 GET_ITER
>> 16 FOR_ITER 6 (to 25)
19 STORE_NAME 0 (x)
2 22 JUMP_ABSOLUTE 16
>> 25 POP_BLOCK
4 26 LOAD_NAME 0 (x)
29 POP_JUMP_IF_TRUE 38
32 LOAD_GLOBAL 1 (AssertionError)
35 RAISE_VARARGS 1
>> 38 LOAD_CONST 3 (None)
41 RETURN_VALUE
Compare to the case with optimizations on:
[steve@ando ~]$ python2.7 -O -c "from dis import dis
code = compile('''\
for x in [1, 2, 3]:
pass
else:
assert x
''', '', 'exec')
dis(code)"""
1 0 SETUP_LOOP 23 (to 26)
3 LOAD_CONST 0 (1)
6 LOAD_CONST 1 (2)
9 LOAD_CONST 2 (3)
12 BUILD_LIST 3
15 GET_ITER
>> 16 FOR_ITER 6 (to 25)
19 STORE_NAME 0 (x)
2 22 JUMP_ABSOLUTE 16
>> 25 POP_BLOCK
4 >> 26 LOAD_CONST 3 (None)
29 RETURN_VALUE
--
Steven
[toc] | [prev] | [next] | [standalone]
| From | Mark Lawrence <breamoreboy@yahoo.co.uk> |
|---|---|
| Date | 2013-12-23 15:22 +0000 |
| Message-ID | <mailman.4560.1387812153.18130.python-list@python.org> |
| In reply to | #62577 |
On 23/12/2013 15:12, Dennis Lee Bieber wrote: > On Mon, 23 Dec 2013 13:33:08 +1100, Steven D'Aprano > <steve+comp.lang.python@pearwood.info> declaimed the following: > >> Roy Smith wrote: >> >> >>> else: >>> assert 0, "can't create picker (classes = %s)" % classes >> >> ¡Ay, caramba! I was with you until the very last line. The above code is >> possibly buggy and inappropriately designed. (I may be completely >> misinterpreting this, in which case feel free to ignore the following >> rant.) >> > > I'd think the biggest problem with this is that if one runs Python with > optimization turned on, the assert statement itself vanishes, leaving one > with an empty else clause... > > Try debugging that problem! > I'll pass on that one :) -- My fellow Pythonistas, ask not what our language can do for you, ask what you can do for our language. Mark Lawrence
[toc] | [prev] | [standalone]
Page 4 of 4 — ← Prev page 1 2 3 [4]
Back to top | Article view | comp.lang.python
csiph-web