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.

classification
Title: New exception syntax
Type: Stage:
Components: None Versions: Python 3.0
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: Nosy List: collinwinter, gvanrossum
Priority: normal Keywords: patch

Created on 2007-01-10 02:12 by collinwinter, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
new_exceptions.patch collinwinter, 2007-01-10 02:12 Implement syntax and compiler changes
doc_fixes.patch collinwinter, 2007-01-10 02:13 Fix documentation and doc-related utilities
fixup.patch collinwinter, 2007-01-10 02:13 Patch the stdlib and other code
Messages (8)
msg51716 - (view) Author: Collin Winter (collinwinter) * (Python committer) Date: 2007-01-10 02:12
The attached patches implement the new "except V as N:" syntax and the solution outlined in http://mail.python.org/pipermail/python-3000/2007-January/005395.html for avoiding exception-related refcount cycles.

new_exceptions.patch is the implementation and tests.
fixup.patch adjusts the stdlib to use the new syntax.
doc_fixes.patch fixes documentation and some docs-related utilities missed by Guido's 2to3 code.

All patches are against r53289.
msg51717 - (view) Author: Collin Winter (collinwinter) * (Python committer) Date: 2007-01-10 02:13
File Added: doc_fixes.patch
msg51718 - (view) Author: Collin Winter (collinwinter) * (Python committer) Date: 2007-01-10 02:13
File Added: fixup.patch
msg51719 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2007-01-10 03:41
Reviewing...  Seems the merge tfrom the 2.6 trunk that Thomas did made some changes to tarfile.py.

Did you have to manually patch anything up after running 2to3/refactor.py -f except on the entire stdlib?

patching file Lib/tarfile.py
Hunk #1 succeeded at 1540 (offset 38 lines).
Hunk #3 succeeded at 1573 (offset 38 lines).
Hunk #5 succeeded at 1745 (offset 38 lines).
Hunk #7 succeeded at 1786 (offset 38 lines).
Hunk #9 FAILED at 1795.
1 out of 9 hunks FAILED -- saving rejects to file Lib/tarfile.py.rej
msg51720 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2007-01-10 05:39
For some strange reason, test_exceptions was wrong.  I'm guessing that the newly added test should be this:
 
    def testExceptionCleanup(self):
        # Make sure "except V as N" exceptions are cleaned up properly
        
        try:
            raise Exception()
        except Exception as e:
            self.failUnless(e)
        self.failIf('e' in locals())

(it had ', e' instead of 'as e', and there was an unneeded 'del e' after self.failUnless(e).)
msg51721 - (view) Author: Collin Winter (collinwinter) * (Python committer) Date: 2007-01-10 14:40
I think there were only four files I had to patch manually after running 2to3; each used automatic exception unpacking.

2to3 successfully fixes Lib/tarfile.py (as of tarfile.py r53336, 2to3 r53339).

The 'del e' in testExceptionCleanup() was indeed needed; it was there to verify that the transformation was

    except V as N:
       try:
          ...
       finally:
          N = None
          del N

and not

    except V as N:
       try:
          ...
       finally:
          del N
msg51722 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2007-01-10 16:23
Thanks!!

Submitted, with tarfile.py and test_exceptions.py corrected (kept the 'del e' in the latter).
Committed revision 53342.

Note: there is now a new test_hotshot failure, probably due to the different code generated for except clauses; I'm keeping this patch open for that.

Is it time to drop the unpacking (sequence) behavior from exceptions altogether, per Brett's PEP?  (That would be a new SF patch.)
msg51723 - (view) Author: Collin Winter (collinwinter) * (Python committer) Date: 2007-01-10 20:00
The hotshot failure may have been related to magic number/bytecode differences, but since a "make clean" resolves the problem, the issue is considered closed (http://mail.python.org/pipermail/python-3000/2007-January/005501.html).
History
Date User Action Args
2022-04-11 14:56:22adminsetgithub: 44437
2008-01-06 22:29:46adminsetkeywords: - py3k
versions: + Python 3.0
2007-01-10 02:12:52collinwintercreate