This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author maggyero
Recipients brett.cannon, docs@python, gvanrossum, maggyero, mark.dickinson, ncoghlan
Date 2019-12-15.11:27:26
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1576409247.01.0.099355858434.issue39037@roundup.psfhosted.org>
In-reply-to
Content
@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)
```
History
Date User Action Args
2019-12-15 11:27:27maggyerosetrecipients: + maggyero, gvanrossum, brett.cannon, mark.dickinson, ncoghlan, docs@python
2019-12-15 11:27:27maggyerosetmessageid: <1576409247.01.0.099355858434.issue39037@roundup.psfhosted.org>
2019-12-15 11:27:26maggyerolinkissue39037 messages
2019-12-15 11:27:26maggyerocreate