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 loewis
Recipients benjamin.peterson, bobbyi, eric.araujo, hfuru, loewis, vstinner
Date 2010-11-13.00:17:12
SpamBayes Score 0.00088069745
Marked as misclassified No
Message-id <4CDDD907.4030906@v.loewis.de>
In-reply-to <1289606565.9.0.191900990967.issue10070@psf.upfronthosting.co.za>
Content
> 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.
History
Date User Action Args
2010-11-13 00:17:15loewissetrecipients: + loewis, hfuru, vstinner, benjamin.peterson, eric.araujo, bobbyi
2010-11-13 00:17:12loewislinkissue10070 messages
2010-11-13 00:17:12loewiscreate