List Info

Thread: 'with' __exit__ doesn't set sys.exc_info()




'with' __exit__ doesn't set sys.exc_info()
country flaguser name
United States
2007-12-18 12:11:01

Can somebody confirm the following behavior is expected: When a ‘with’ statement invokes __exit__(), it looks like sys.exc_info() is not actually set.

 

I know this may be a very pedantic detail,  but I’m working on IronPython and would like to make it consistent with CPython217;s behavior.

 

The PEP (http://www.python.org/dev/peps/pep-0343/ ) says that ‘With’ can be substituted as follows:

 

        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:

           ;     # The exceptional case is handled here

           ;     exc = False

           ;     if not exit(*sys.exc_info()):

           ;         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)

 

and that “The details of the above translation are intended to prescribe the exact semantics.”. This implies that sys.exc_info() would be set when exit is invoked.

 

I’m finding in practice that sys.exc_info() is not set when __exit__() is invoked in the exceptional case.   I attached a simple repro (repro.py) to demonstrate exactly what I mean.

 

Can somebody confirm this is the expected behavior?

 

Thanks,

Mike

http://blogs.msdn.com/jmstall

 

 

  
Re: 'with' __exit__ doesn't set sys.exc_info()
user name
2007-12-18 12:44:17
Since no actual except clause is used, this is reasonable,
and I
wouldn't want it changed. I guess the PEP overstated the
exactness of
the translation. Suggestions for better wording are
accepted.

On Dec 18, 2007 10:11 AM, Mike Stall <jmstallexchange.microsoft.com> wrote:
>
>
>
>
> Can somebody confirm the following behavior is
expected: When a 'with'
> statement invokes __exit__(), it looks like
sys.exc_info() is not actually
> set.
>
>
>
> I know this may be a very pedantic detail,  but I'm
working on IronPython
> and would like to make it consistent with CPython's
behavior.
>
>
>
> The PEP (http://www.p
ython.org/dev/peps/pep-0343/ ) says that 'With' can be
> substituted as follows:
>
>
>
>         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:
>
>                 # The exceptional case is handled here
>
>                 exc = False
>
>                 if not exit(*sys.exc_info()):
>
>                     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)
>
>
>
> and that "The details of the above translation are
intended to prescribe the
> exact semantics.". This implies that
sys.exc_info() would be set when exit
> is invoked.
>
>
>
> I'm finding in practice that sys.exc_info() is not set
when __exit__() is
> invoked in the exceptional case.   I attached a simple
repro (repro.py) to
> demonstrate exactly what I mean.
>
>
>
> Can somebody confirm this is the expected behavior?
>
>
>
> Thanks,
>
> Mike
>
> http://blogs.msdn.com/j
mstall
>
>
>
>
> _______________________________________________
> Python-Dev mailing list
> Python-Devpython.org
> ht
tp://mail.python.org/mailman/listinfo/python-dev
> Unsubscribe:
> http://mail.python.org/mailman/options/pytho
n-dev/guido%40python.org
>
>



-- 
--Guido van Rossum (home page: http://www.python.org/~
guido/)
_______________________________________________
Python-Dev mailing list
Python-Devpython.org
ht
tp://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: http://mail.python.org/mailman/options/p
ython-dev/nessto%40sharedlog.com

[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )