Message358416
@gvanrossum
By the way, is there any particular reason why the ``try`` statement implementation equivalent to the ``with`` statement given in PEP 343 puts the finally clause in an outer ``try`` statement instead of in the inner ``try`` statement? (cf. https://www.python.org/dev/peps/pep-0343/#specification-the-with-statement)
In other words, couldn't we simplify this:
```
mgr = (EXPR)
exit = type(mgr).__exit__ # Not calling it yet
value = type(mgr).__enter__(mgr)
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(mgr, *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(mgr, None, None, None)
```
into that?
```
mgr = (EXPR)
exit = type(mgr).__exit__ # Not calling it yet
value = type(mgr).__enter__(mgr)
exc = True
try:
VAR = value # Only if "as VAR" is present
BLOCK
except:
# The exceptional case is handled here
exc = False
if not exit(mgr, *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(mgr, None, None, None)
``` |
|
Date |
User |
Action |
Args |
2019-12-15 11:27:27 | maggyero | set | recipients:
+ maggyero, gvanrossum, brett.cannon, mark.dickinson, ncoghlan, docs@python |
2019-12-15 11:27:27 | maggyero | set | messageid: <1576409247.01.0.099355858434.issue39037@roundup.psfhosted.org> |
2019-12-15 11:27:26 | maggyero | link | issue39037 messages |
2019-12-15 11:27:26 | maggyero | create | |
|