[issue10070] 2to3 wishes for already-2to3'ed files

Martin v. Löwis report at bugs.python.org
Sat Nov 13 07:53:13 CET 2010


Martin v. Löwis <martin at v.loewis.de> added the comment:

> Consider here:
> http://www.sqlalchemy.org/trac/browser/lib/sqlalchemy/engine/base.py?rev=6884:b181f1e53603#L1329
> the py3k code uses the "raise ... from" syntax which isn't legal in Python 2. 

In this case, I would write

   error = exc.DBAPIError.instance(statement,
                            parameters,
                            e,
                            connection_invalidated=is_disconnect)
   if sys.version_info < (3,):
       raise error, None, sys.exc_info()[2]
   else:
       error.__cause__ = e
       raise error

You don't *have* to use the from syntax to set the cause.

> Approach B isn't a general solution because it requires you to replace entire functions at a time. 

I don't claim that. However, I claim that there will be always an
appropriate solution using existing techniques, so that such a macro
processing wouldn't be necessary. IOW, I'm not aware of a case where
using such preprocessing would be appropriate and better than what
you can do without.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue10070>
_______________________________________


More information about the Python-bugs-list mailing list