Re: try..except with empty exceptions

2015-04-12 Thread Cameron Simpson
On 12Apr2015 17:00, Chris Angelico wrote: On Sun, Apr 12, 2015 at 4:33 PM, Cameron Simpson wrote: [...] That's what try/finally is for. You can do your cleanup without caring exactly what was raised. Hmm, yes. [...] However, my Asynchron class really is a little special. I use Asynchron t

Re: try..except with empty exceptions

2015-04-12 Thread Chris Angelico
On Sun, Apr 12, 2015 at 4:33 PM, Cameron Simpson wrote: > On 12Apr2015 09:21, Chris Angelico wrote: >> Fair enough. Do you know how often you actually catch stuff that >> wouldn't be caught by "except BaseException:"? > > > I don't know and I'm not sure I care (but discussion below). I would need

Re: try..except with empty exceptions

2015-04-11 Thread Cameron Simpson
On 12Apr2015 14:18, Steven D'Aprano wrote: On Sun, 12 Apr 2015 09:08 am, Cameron Simpson wrote: Also, IMO, a bare "except:" syntax is far more pleasing to the eye than "except magic_exception_name_that+gets_everything:". And that is exactly what makes bare excepts an attractive nuisance! I'

Re: try..except with empty exceptions

2015-04-11 Thread Cameron Simpson
On 12Apr2015 16:33, Cameron Simpson wrote: Finally, if we were to expunge support for "except:", one would also need a cast iron guarrentee that no exception could possibly occur which was not a subclass of BaseException. I'd expect that to mean that "raise" of a non-instance of BaseException

Re: try..except with empty exceptions

2015-04-11 Thread Cameron Simpson
On 12Apr2015 09:21, Chris Angelico wrote: On Sun, Apr 12, 2015 at 9:08 AM, Cameron Simpson wrote: Catching all exceptions isn't terribly common, _except_ in service routines that wrap "unknown" operations. Classic example from my Asynchron class: [...] try: r = func(*a, **kw)

Re: try..except with empty exceptions

2015-04-11 Thread Steven D'Aprano
On Sun, 12 Apr 2015 09:08 am, Cameron Simpson wrote: > Also, IMO, a bare "except:" syntax is far more pleasing to the eye than > "except magic_exception_name_that+gets_everything:". And that is exactly what makes bare excepts an attractive nuisance! I'm going to channel a newbie, cowboy or just

Re: try..except with empty exceptions

2015-04-11 Thread Steven D'Aprano
On Sun, 12 Apr 2015 07:37 am, Cameron Simpson wrote: > On 11Apr2015 21:21, Chris Angelico wrote: >>But I agree, it would be very nice if Python 3 could have abolished >>the truly confusing part of this, where "except:" catches everything. >>Forcing people to spell it "except BaseException:" would

Re: try..except with empty exceptions

2015-04-11 Thread Chris Angelico
On Sun, Apr 12, 2015 at 9:08 AM, Cameron Simpson wrote: > Catching all exceptions isn't terribly common, _except_ in service routines > that wrap "unknown" operations. Classic example from my Asynchron class: > >def call(self, func, *a, **kw): > ''' Have the Asynchron call `func(*a,**kw)`

Re: try..except with empty exceptions

2015-04-11 Thread Cameron Simpson
On 12Apr2015 07:52, Chris Angelico wrote: On Sun, Apr 12, 2015 at 7:37 AM, Cameron Simpson wrote: On 11Apr2015 21:21, Chris Angelico wrote: But I agree, it would be very nice if Python 3 could have abolished the truly confusing part of this, where "except:" catches everything. Forcing people

Re: try..except with empty exceptions

2015-04-11 Thread Chris Angelico
On Sun, Apr 12, 2015 at 7:37 AM, Cameron Simpson wrote: > On 11Apr2015 21:21, Chris Angelico wrote: >> >> But I agree, it would be very nice if Python 3 could have abolished >> the truly confusing part of this, where "except:" catches everything. >> Forcing people to spell it "except BaseExceptio

Re: try..except with empty exceptions

2015-04-11 Thread Cameron Simpson
On 11Apr2015 21:21, Chris Angelico wrote: But I agree, it would be very nice if Python 3 could have abolished the truly confusing part of this, where "except:" catches everything. Forcing people to spell it "except BaseException:" would fix all of this. How hard is it to deprecate and then remov

Re: try..except with empty exceptions

2015-04-11 Thread Chris Angelico
On Sun, Apr 12, 2015 at 6:04 AM, Chris Angelico wrote: > On Sun, Apr 12, 2015 at 4:49 AM, Ian Kelly wrote: >> On Apr 11, 2015 5:06 AM, "Steven D'Aprano" >> wrote: >>> >>> Yes, I agree that Python's behaviour here is better than the alternative. >>> Having "except ()" catch nothing is consistent

Re: try..except with empty exceptions

2015-04-11 Thread Chris Angelico
On Sun, Apr 12, 2015 at 4:49 AM, Ian Kelly wrote: > On Apr 11, 2015 5:06 AM, "Steven D'Aprano" > wrote: >> >> Yes, I agree that Python's behaviour here is better than the alternative. >> Having "except ()" catch nothing is consistent with the behaviour with >> other tuples, so I'm okay with that.

Re: try..except with empty exceptions

2015-04-11 Thread Ian Kelly
On Apr 11, 2015 5:06 AM, "Steven D'Aprano" < steve+comp.lang.pyt...@pearwood.info> wrote: > > Yes, I agree that Python's behaviour here is better than the alternative. > Having "except ()" catch nothing is consistent with the behaviour with > other tuples, so I'm okay with that. But it still surpri

Re: try..except with empty exceptions

2015-04-11 Thread Ian Foote
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 On 11/04/15 08:11, Steven D'Aprano wrote: > But with try...except, an empty exception list means to catch > *everything*, not nothing: > > try: ... except a,b,c: # catches a, b, c > > try: ... except a,b: # catches a, b This example is incorrect. In

Re: try..except with empty exceptions

2015-04-11 Thread Chris Angelico
On Sat, Apr 11, 2015 at 9:00 PM, Steven D'Aprano wrote: > Yes, I agree that Python's behaviour here is better than the alternative. > Having "except ()" catch nothing is consistent with the behaviour with > other tuples, so I'm okay with that. But it still surprised me :-) It's worth noting that

Re: try..except with empty exceptions

2015-04-11 Thread Steven D'Aprano
On Sat, 11 Apr 2015 07:27 pm, Cameron Simpson wrote: > If the empty tuple were to mean "catch everything" then there would not be > a way to express "catch nothing". Bad bad bad! # Catch everything: try: spam() except: pass # Catch nothing: spam() :-) > Consider this a proof that Py

Re: try..except with empty exceptions

2015-04-11 Thread Steven D'Aprano
On Sat, 11 Apr 2015 06:22 pm, Serhiy Storchaka wrote: > On 11.04.15 10:11, Steven D'Aprano wrote: >> Anyway, in modern Python (2.6 onwards), now that string exceptions are >> gone, you can supply something to catch everything. Or nothing, for that >> matter: >> >> BaseException # catch everything

Re: try..except with empty exceptions

2015-04-11 Thread Dave Angel
On 04/11/2015 06:14 AM, Dave Angel wrote: On 04/11/2015 03:11 AM, Steven D'Aprano wrote: On Sat, 11 Apr 2015 12:23 pm, Dave Angel wrote: On 04/10/2015 09:42 PM, Steven D'Aprano wrote: On Sat, 11 Apr 2015 05:31 am, sohcahto...@gmail.com wrote: It isn't document because it is expected. Why w

Re: try..except with empty exceptions

2015-04-11 Thread Dave Angel
On 04/11/2015 03:11 AM, Steven D'Aprano wrote: On Sat, 11 Apr 2015 12:23 pm, Dave Angel wrote: On 04/10/2015 09:42 PM, Steven D'Aprano wrote: On Sat, 11 Apr 2015 05:31 am, sohcahto...@gmail.com wrote: It isn't document because it is expected. Why would the exception get caught if you're not

Re: try..except with empty exceptions

2015-04-11 Thread Cameron Simpson
On 10Apr2015 19:38, Rustom Mody wrote: On Saturday, April 11, 2015 at 7:53:31 AM UTC+5:30, Dave Angel wrote: On 04/10/2015 09:42 PM, Steven D'Aprano wrote: > On Sat, 11 Apr 2015 05:31 am, sohcahtoa82 wrote: >> It isn't document because it is expected. Why would the exception get >> caught if y

Re: try..except with empty exceptions

2015-04-11 Thread Terry Reedy
On 4/10/2015 9:42 PM, Steven D'Aprano wrote: try: spam() except: # Implicitly an empty tuple. pass No, specified as equivalent to 'except BaseException:' (or 'except (BaseException,):', either of which are different from 'except ():'. "An expression-less except clause, if prese

Re: try..except with empty exceptions

2015-04-11 Thread Serhiy Storchaka
On 11.04.15 10:11, Steven D'Aprano wrote: Anyway, in modern Python (2.6 onwards), now that string exceptions are gone, you can supply something to catch everything. Or nothing, for that matter: BaseException # catch everything Not everything. >>> class A: pass ... >>> try: raise A ... except

Re: try..except with empty exceptions

2015-04-11 Thread Steven D'Aprano
On Sat, 11 Apr 2015 12:23 pm, Dave Angel wrote: > On 04/10/2015 09:42 PM, Steven D'Aprano wrote: >> On Sat, 11 Apr 2015 05:31 am, sohcahto...@gmail.com wrote: >> >>> It isn't document because it is expected. Why would the exception get >>> caught if you're not writing code to catch it? If you wr

Re: try..except with empty exceptions

2015-04-10 Thread Rustom Mody
On Saturday, April 11, 2015 at 9:47:36 AM UTC+5:30, Rustom Mody wrote: > On Saturday, April 11, 2015 at 9:17:16 AM UTC+5:30, Dave Angel wrote: > > On 04/10/2015 10:38 PM, Rustom Mody wrote: > > > On Saturday, April 11, 2015 at 7:53:31 AM UTC+5:30, Dave Angel wrote: > > >> On 04/10/2015 09:42 PM, St

Re: try..except with empty exceptions

2015-04-10 Thread Rustom Mody
On Saturday, April 11, 2015 at 9:17:16 AM UTC+5:30, Dave Angel wrote: > On 04/10/2015 10:38 PM, Rustom Mody wrote: > > On Saturday, April 11, 2015 at 7:53:31 AM UTC+5:30, Dave Angel wrote: > >> On 04/10/2015 09:42 PM, Steven D'Aprano wrote: > >>> On Sat, 11 Apr 2015 05:31 am, sohcahtoa82 wrote: > >

Re: try..except with empty exceptions

2015-04-10 Thread Dave Angel
On 04/10/2015 10:38 PM, Rustom Mody wrote: On Saturday, April 11, 2015 at 7:53:31 AM UTC+5:30, Dave Angel wrote: On 04/10/2015 09:42 PM, Steven D'Aprano wrote: On Sat, 11 Apr 2015 05:31 am, sohcahtoa82 wrote: It isn't document because it is expected. Why would the exception get caught if you

Re: try..except with empty exceptions

2015-04-10 Thread Rustom Mody
On Saturday, April 11, 2015 at 7:53:31 AM UTC+5:30, Dave Angel wrote: > On 04/10/2015 09:42 PM, Steven D'Aprano wrote: > > On Sat, 11 Apr 2015 05:31 am, sohcahtoa82 wrote: > > > >> It isn't document because it is expected. Why would the exception get > >> caught if you're not writing code to catch

Re: try..except with empty exceptions

2015-04-10 Thread Dave Angel
On 04/10/2015 09:42 PM, Steven D'Aprano wrote: On Sat, 11 Apr 2015 05:31 am, sohcahto...@gmail.com wrote: It isn't document because it is expected. Why would the exception get caught if you're not writing code to catch it? If you write a function and pass it a tuple of exceptions to catch, I'

Re: try..except with empty exceptions

2015-04-10 Thread Rustom Mody
On Friday, April 10, 2015 at 2:18:22 PM UTC+5:30, Pavel S wrote: > Hi, > > I noticed interesting behaviour. Since I don't have python3 installation > here, I tested that on Python 2.7. > > Well known feature is that try..except block can catch multiple exceptions > listed in a tuple: > > > ex

Re: try..except with empty exceptions

2015-04-10 Thread Steven D'Aprano
On Sat, 11 Apr 2015 05:31 am, sohcahto...@gmail.com wrote: > It isn't document because it is expected. Why would the exception get > caught if you're not writing code to catch it? If you write a function > and pass it a tuple of exceptions to catch, I'm not sure why you would > expect it to catc

Re: try..except with empty exceptions

2015-04-10 Thread Dave Angel
On 04/10/2015 04:48 AM, Pavel S wrote: Hi, I noticed interesting behaviour. Since I don't have python3 installation here, I tested that on Python 2.7. Well known feature is that try..except block can catch multiple exceptions listed in a tuple: exceptions = ( TypeError, ValueError ) try: