Re: Raise X or Raise X()?

2012-03-12 Thread Jean-Michel Pichavant
bvdp wrote: Which is preferred in a raise: X or X()? I've seen both. In my specific case I'm dumping out of a deep loop: try: for ... for ... for ... if match: raise StopInteration() else ... except StopInteration: print found it I prefer

Re: Raise X or Raise X()?

2012-03-12 Thread Robert Kern
On 3/12/12 10:37 AM, Jean-Michel Pichavant wrote: bvdp wrote: Which is preferred in a raise: X or X()? I've seen both. In my specific case I'm dumping out of a deep loop: try: for ... for ... for ... if match: raise StopInteration() else ... except StopInteration: print found it I prefer

Re: Raise X or Raise X()?

2012-03-12 Thread James Elford
On 11/03/12 19:04, bvdp wrote: Which is preferred in a raise: X or X()? I've seen both. In my specific case I'm dumping out of a deep loop: try: for ... for ... for ... if match: raise StopInteration() else ... except StopInteration: print

Re: Raise X or Raise X()?

2012-03-12 Thread Chris Angelico
On Tue, Mar 13, 2012 at 12:06 AM, James Elford fil.ora...@gmail.com wrote: I wonder whether you need to use an exception here rather than a yield statement? Or a return statement, if you're not needing multiple responses. ChrisA -- http://mail.python.org/mailman/listinfo/python-list

Re: Raise X or Raise X()?

2012-03-12 Thread Stefan Behnel
Irmen de Jong, 11.03.2012 21:37: On 11-3-2012 20:04, bvdp wrote: Which is preferred in a raise: X or X()? I've seen both. In my specific case I'm dumping out of a deep loop: try: for ... for ... for ... if match: raise StopInteration() else

Re: Raise X or Raise X()?

2012-03-12 Thread Steven D'Aprano
On Mon, 12 Mar 2012 14:52:49 +0100, Stefan Behnel wrote: raise X is a special case of the 3-args raise. Effectively it just raises an instance of X which is constructed with an empty argument list. Therefore, raise X() is equivalent, as far as I know. Not completely, although that may

Re: Raise X or Raise X()?

2012-03-12 Thread Stefan Behnel
Steven D'Aprano, 12.03.2012 16:08: On Mon, 12 Mar 2012 14:52:49 +0100, Stefan Behnel wrote: raise X is a special case of the 3-args raise. Effectively it just raises an instance of X which is constructed with an empty argument list. Therefore, raise X() is equivalent, as far as I know

Raise X or Raise X()?

2012-03-11 Thread bvdp
Which is preferred in a raise: X or X()? I've seen both. In my specific case I'm dumping out of a deep loop: try: for ... for ... for ... if match: raise StopInteration() else ... except StopInteration: print found it -- http://mail.python.org/mailman

Re: Raise X or Raise X()?

2012-03-11 Thread Irmen de Jong
On 11-3-2012 20:04, bvdp wrote: Which is preferred in a raise: X or X()? I've seen both. In my specific case I'm dumping out of a deep loop: try: for ... for ... for ... if match: raise StopInteration() else ... except StopInteration

Re: Raise X or Raise X()?

2012-03-11 Thread Chris Rebert
On Sun, Mar 11, 2012 at 1:37 PM, Irmen de Jong irmen.nos...@xs4all.nl wrote: On 11-3-2012 20:04, bvdp wrote: Which is preferred in a raise: X or X()? I've seen both. In my specific case I'm dumping out of a deep loop: try:   for ...     for ...       for ...         if match

Re: Raise X or Raise X()?

2012-03-11 Thread Steven D'Aprano
On Sun, 11 Mar 2012 12:04:55 -0700, bvdp wrote: Which is preferred in a raise: X or X()? Both. Always use raise X(*args) when you need to provide arguments (which you should always do for exceptions meant for the caller to see). The form raise X, args should be considered discouraged

Re: Raise X or Raise X()?

2012-03-11 Thread bvdp
Thanks all for the comments. Personally, I used raise X to mean this doesn't need arguments and should never have any and raise X() to mean this needs arguments but I'm too lazy to provide them right now. Think of it as a FIXME. Yes, that makes as much sense as anything else :) -- http

Re: Raise X or Raise X()?

2012-03-11 Thread MRAB
On 11/03/2012 23:59, Steven D'Aprano wrote: On Sun, 11 Mar 2012 12:04:55 -0700, bvdp wrote: Which is preferred in a raise: X or X()? Both. Always use raise X(*args) when you need to provide arguments (which you should always do for exceptions meant for the caller to see). The form raise X