homepage

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 bobbyi
Recipients benjamin.peterson, bobbyi, eric.araujo, hfuru, loewis, vstinner
Date 2010年11月13日.00:02:43
SpamBayes Score 0.00015687678
Marked as misclassified No
Message-id <1289606565.9.0.191900990967.issue10070@psf.upfronthosting.co.za>
In-reply-to
Content
> Can you please post an example Python module that has this markup you are asking for, so I can show you how to achieve what you want without the markup?
Hi, Martin. Here's a real-world example:
http://www.sqlalchemy.org/trac/browser/lib/sqlalchemy/types.py?rev=6884:b181f1e53603
The syntax is:
# Py3K
# <python 3 code>
# Py2K
<python 2 code>
# end Py2K
For example, starting on line 152 we have,
 # Py3K
 #return unicode(self.compile())
 # Py2K
 return unicode(self.compile()).\
 encode('ascii', 'backslashreplace')
 # end Py2K
When the code is converted with 2to3, the py3k code on line 153 will be uncommented and used to replace the py2k code on lines 155-156. Having the py3k version commented before conversion resolves the issue that "you must not use syntax that is exclusively Python 3 in an if-python3 block".
Here is their modified version of 2to3 to support this syntax:
http://www.sqlalchemy.org/trac/browser/sa2to3.py
Their explanation is:
"This tool monkeypatches a preprocessor onto lib2to3.refactor.RefactoringTool, so that conditional sections can replace non-fixable Python 2 code sections for the appropriate Python 3 version before 2to3 is run."
History
Date User Action Args
2010年11月13日 00:02:45bobbyisetrecipients: + bobbyi, loewis, hfuru, vstinner, benjamin.peterson, eric.araujo
2010年11月13日 00:02:45bobbyisetmessageid: <1289606565.9.0.191900990967.issue10070@psf.upfronthosting.co.za>
2010年11月13日 00:02:43bobbyilinkissue10070 messages
2010年11月13日 00:02:43bobbyicreate

AltStyle によって変換されたページ (->オリジナル) /