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

Martin v. Löwis report at bugs.python.org
Sat Nov 13 01:17:15 CET 2010


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

> For example, starting on line 152 we have,
>         # Py3K
>         #return unicode(self.compile())
>         # Py2K
>         return unicode(self.compile()).\
>                         encode('ascii', 'backslashreplace')
>         # end Py2K

Ok, I can propose two different spellings of this without any
macro processor:

A. conditionally encode for 2.x

   def __str__(self):
       res = unicode(self.compile())
       if sys.version_info < (3,):
           res = res.encode('ascii', 'backslashreplace')
       return res

B. (if A is deemed to incur too much per-call cost, due to
   the version test)

   if sys.version_info >= (3,):
       def __str__(self):
           return unicode(self.compile())
   else:
       def __str__(self):
           return unicode(self.compile()). \
                  encode('ascii', 'backslashreplace')

In addition, I fail to see how the markup hfuru proposed can be
used to express this case. IIUC, he asks for markup that can tell
2to3 to leave a certain piece of code alone, i.e. unmodified. I
fail to see how this would help in this sqlalchemy example.

----------

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


More information about the Python-bugs-list mailing list