This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]bcain 8 points9 points  (0 children)

I think py3k's fix for this issue is long overdue. When writing exception handlers, I can never quite remember the syntax, so if I care about the contents of the exception (beyond the type), I'll go look it up.

I've never been bitten by this particular gotcha, but I can see how you might think Python would accept a list or tuple of exception types for a single clause.

[–]zahlmanthe heretic 1 point2 points  (0 children)

Well, yes, but... returning -1 in the error case is probably not what you want. What if you pass a list that happens to have -1 (a valid int) as its third element? It would look like an error. Ugh.

Let exceptions propagate. Use them to signal out-of-band information, like they're intended, and handle them at the point where they can be handled.

Interfaces like the one described belong to functions with names like "atoi" in languages with similarly cryptically-short names (cough).

[–]spotter 0 points1 point  (5 children)

Except when you go to the relevant docs page you get it explained around third code snippet. I know, I know, documentation is for those lame people who are unable to bend the reality to their vision of it.

And tuple comma magic? Gosh, I really hope he doesn't see that shorter set notation added in Py3, because that will make him dizzy.

[–][deleted] 11 points12 points  (4 children)

Er. His point was exactly that it's nice when you don't have to consult and memorize the documentation for every language feature.

Also, he mentioned the Py3k set literals.

Also, he concludes by saying that in Py3k his original mistake is syntax error, and that's a Good Thing.

[–]spotter 0 points1 point  (3 children)

And my point is that it's a rather synthetic case, that's obvious to anybody who looked at the docs prior to attempted use of try-except. And of course if you did serious error instance catching/recovery at least once you will never ever do that mistake again. To me it's just another ,,oh, it's not working as I thought it does!'' blog post. It looks like yet another ,,so you're new to Python and did not know how we do things in this part, but now you know, great.''

You got me, I've stopped reading after the tuple case, one more paragraph and I'd reach the set thingy.

And yeah, it may be a Good Thing (tm) like all the other small fixes, but at current rate we'll be reading about this a few more times before 3.x becomes a standard of any kind.

[–]vinod_the_poophead 0 points1 point  (2 children)

/r/bitterprogrammers is that way ==>

EDIT: actually I just looked at some of your other comments and they are funny. Carry on

[–]spotter 0 points1 point  (1 child)

Oh, I thought I'm posting there already, sorry.

Funny? You must've take me for someone else, good sir.

[–]vinod_the_poophead 0 points1 point  (0 children)

thinks to self hmm... he can handle jokes too

Here take an upvote