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.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
repro.py
Description: repro.py
_______________________________________________ Python-Dev mailing list Python-Dev@python.org http://mail.python.org/mailman/listinfo/python-dev Unsubscribe: http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com