[Python-3000] Pre-peps on raise and except changes (was: Warning for 2.6 and greater)
Collin Winter
collinw at gmail.com
Sat Feb 10 05:52:15 CET 2007
On 2/9/07, Phillip J. Eby <pje at telecommunity.com> wrote:
> At 05:03 PM 2/9/2007 -0800, Guido van Rossum wrote:
> >On 2/9/07, Collin Winter <collinw at gmail.com> wrote:
> > > sys.exc_info() will be kept, while the sys.exc_{type,value,traceback}
> > > attributes will be dropped.
> >
> >I understand why, but that doesn't make me uncomfortable with keeping
> >it. Maybe in "3.0 compatibility mode" 2.6 could attach tracebacks to
> >exception objects so we could be weened off it in 2.6?
>
> I notice that neither PEP addresses PEP 343 compatibility. Do we plan to
> make __exit__() only get one argument? Right now the protocol demands all
> three. I suppose we could pass one argument in 3.0, and if you want to
> support 2.6 you would have to add default arguments. Such code would be
> ugly as sin, but workable.
Couldn't __exit__() be passed (type(e), e, e.__traceback__) instead of
*sys.exc_info()? That is, the source translation given in PEP 343
becomes
mgr = (EXPR)
exit = mgr.__exit__ # Not calling it yet
value = mgr.__enter__()
exc = True
try:
try:
VAR = value # Only if "as VAR" is present
BLOCK
except Exception as e:
# The exceptional case is handled here
exc = False
if not exit(type(e), e, e.__traceback__):
raise
# The exception is swallowed if exit() returns true
finally:
# The normal and non-local-goto cases are handled here
if exc:
exit(None, None, None)
Collin Winter
More information about the Python-3000
mailing list