[Robin Becker]
The 2.0 docs clearly state 'The optional else clause is executed when no exception occurs in the try clause.' This makes it sound as though it gets executed on the 'way out'.
Of course. That's not what the docs meant, though, and Guido is not going to change the implementation now because that would break code that relies on how Python has always *worked* in these cases. The way Python works is also the way Guido intended it to work (I'm allowed to channel him when he's on vacation <0.9 wink)>. Indeed, that's why I suggested a specific doc change. If your friend would also be confused by that, then we still have a problem; else we don't.
On Fri, Dec 29, 2000 at 03:27:40PM -0500, Tim Peters wrote:
Indeed, that's why I suggested a specific doc change. If your friend would also be confused by that, then we still have a problem; else we don't.
Note that I already uploaded a patch to fix the docs, assigned to fdrake, using Tim's wording exactly. (patch #103045) -- Thomas Wouters <thomas@xs4all.net> Hi! I'm a .signature virus! copy me into your .signature file to help me spread!
Thomas just checked this in, using Tim's words:
*** ref7.tex 2000/07/16 19:05:38 1.20 --- ref7.tex 2000/12/31 22:52:59 1.21 *************** *** 243,249 **** \ttindex{exc_value}\ttindex{exc_traceback}}
! The optional \keyword{else} clause is executed when no exception occurs ! in the \keyword{try} clause. Exceptions in the \keyword{else} clause are ! not handled by the preceding \keyword{except} clauses. \kwindex{else}
--- 243,251 ---- \ttindex{exc_value}\ttindex{exc_traceback}}
! The optional \keyword{else} clause is executed when the \keyword{try} clause ! terminates by any means other than an exception or executing a ! \keyword{return}, \keyword{continue} or \keyword{break} statement. ! Exceptions in the \keyword{else} clause are not handled by the preceding ! \keyword{except} clauses. \kwindex{else}
How is this different from "when control flow reaches the end of the try clause", which is what I really had in mind? Using the current wording, this paragraph would have to be changed each time a new control-flow keyword is added. Based upon the historical record that's not a grave concern ;-), but I think the new wording relies too much on accidentals such as the fact that these are the only control flow altering events. It may be that control flow is not rigidly defined -- but as it is what was really intended, maybe the fix should be to explain the right concept rather than the current ad-hoc solution. This also avoids concerns of readers who are trying to read too much into the words and might become worried that there are other ways of altering the control flow that *would* cause the else clause to be executed; and guides implementors of other Pyhon-like languages (like vyper) that might have more control-flow altering statements or events. --Guido van Rossum (home page: http://www.python.org/~guido/)
[Guido]
Thomas just checked this in, using Tim's words:
[ The optional \keyword{else} clause is executed when no exception occurs in the \keyword{try} clause. Exceptions in the \keyword{else} clause are not handled by the preceding \keyword{except} clauses. vs The optional \keyword{else} clause is executed when the \keyword{try} clause terminates by any means other than an exception or executing a \keyword{return}, \keyword{continue} or \keyword{break} statement. Exceptions in the \keyword{else} clause are not handled by the preceding \keyword{except} clauses. ]
How is this different from "when control flow reaches the end of the try clause", which is what I really had in mind?
Only in that it doesn't appeal to a new undefined phrase, and is (I think) unambiguous in the eyes of a non-specialist reader (like Robin's friend). Note that "reaching the end of the try clause" is at best ambiguous, because you *really* have in mind "falling off the end" of the try clause. It wouldn't be unreasonable to say that in: try: x = 1 y = 2 return 1 "x=1" is the beginning of the try clause and "return 1" is the end. So if the reader doesn't already know what you mean, saying "the end" doesn't nail it (or, if like me, the reader does already know what you mean, it doesn't matter one whit what it says <wink>).
Using the current wording, this paragraph would have to be changed each time a new control-flow keyword is added. Based upon the historical record that's not a grave concern ;-),
It was sure no concern of mine ...
but I think the new wording relies too much on accidentals such as the fact that these are the only control flow altering events.
It may be that control flow is not rigidly defined -- but as it is what was really intended, maybe the fix should be to explain the right concept rather than the current ad-hoc solution. ...
OK, except I don't know how to do that succinctly. For example, if Java had an "else" clause, the Java spec would say: If present, the "else block" is executed if and only if execution of the "try block" completes normally, and then there is a choice: If the "else block" completes normally, then the "try" statement completes normally. If the "else block" completes abruptly for reason S, then the "try" statement completes abruptly for reason S. That is, they deal with control-flow issues via appeal to "complete normally" and "complete abruptly" (which latter comes in several flavors ("reasons"), such as returns and exceptions), and there are pages and pages and pages of stuff throughout the spec inductively defining when these conditions obtain. It's clear, precise and readable; but it's also wordy, and we don't have anything similar to build on. As a compromise, given that we're not going to take the time to be precise (well, I'm sure not ...): The optional \keyword{else} clause is executed if and when control flows off the end of the \keyword{try} clause.\foonote{In Python 2.0, control "flows off the end" except in case of exception, or executing a \keyword{return}, \keyword{continue} or \keyword{break} statement.} Exceptions in the \keyword{else} clause are not handled by the preceding \keyword{except} clauses. Now it's all of imprecise, almost precise, specific to Python 2.0, and robust against any future changes <wink>.
As a compromise, given that we're not going to take the time to be precise (well, I'm sure not ...):
The optional \keyword{else} clause is executed if and when control flows off the end of the \keyword{try} clause.\foonote{In Python 2.0, control "flows off the end" except in case of exception, or executing a \keyword{return}, \keyword{continue} or \keyword{break} statement.} Exceptions in the \keyword{else} clause are not handled by the preceding \keyword{except} clauses.
Now it's all of imprecise, almost precise, specific to Python 2.0, and robust against any future changes <wink>.
Sounds good to me. The reference to 2.0 could be changed to "Currently". --Guido van Rossum (home page: http://www.python.org/~guido/)
The optional \keyword{else} clause is executed if and when control flows off the end of the \keyword{try} clause.\foonote{In Python 2.0, control "flows off the end" except in case of exception, or executing a \keyword{return}, \keyword{continue} or \keyword{break} statement.} Exceptions in the \keyword{else} clause are not handled by the preceding \keyword{except} clauses.
[Guido]
Sounds good to me. The reference to 2.0 could be changed to "Currently".
Cool. See http://sourceforge.net/bugs/?group_id=5470&func=detailbug&bug_id=127098
participants (3)
-
Guido van Rossum
-
Thomas Wouters
-
Tim Peters