[issue28143] ASDL compatibility with Python 3 system interpreter

Martin Panter report at bugs.python.org
Fri Sep 23 23:28:06 EDT 2016


Martin Panter added the comment:

That would get the patch mostly working with 2.6+. Is it okay to break Python < 2.6 support? I know there was an OS X Tiger buildbot using 2.5 until recently; see Issue 28039.

Personally, I would rather focus on the problems with make dependencies, build configuration, etc, rather than changing what versions of Python the code runs on.

Regarding CRLFs on Windows: the existing code opens files in binary mode (wb), so Windows will not translate \n into CRLF. Changing this behaviour is separate to the goal of Python 3 compatibility. IMO the build process should not change the contents of checked-in files, regardless of whether there is a version control system like Mercurial or Git in use or not. See also Issue 27425.

On the other hand, the Python 3 code does use text mode with CRLF translation, so maybe it is not a big deal. (I never built Python on Windows, so I don’t know.)

+++ b/Parser/spark.py
@@ -171,7 +171,7 @@ class GenericParser:
-    rules = string.split(doc)
+    rules = str.split(doc)

This would read better as doc.split(); see <http://svn.python.org/view?view=revision&revision=55143>.

@@ -825,15 +828,15 @@ class GenericASTMatcher(GenericParser):
-    print '\t', item
+    print('\t', item)
     for (lhs, rhs), pos in states[item[0]].items:
-        print '\t\t', lhs, '::=',
+        print('\t\t', lhs, '::=', end=" ")
. . .
+        print(string.join(rhs[:pos]), end=" ")
+        print('.', end=" ")
+        print(string.join(rhs[pos:]))

The string quoting is inconsistent. Also, I suspect string.join() is not right for Python 3. And you are adding an extra space after the '\t' characters.

For what it’s worth, here are some similar changes made to the Py 3 branch:

r57749: raise syntax
r51578: `. . .` → repr()
http://svn.python.org/view?view=revision&revision=55329: Unpack tuples inside functions (Malthe’s patch unpacks as the function is called instead); map() → list comprehension
http://svn.python.org/view?view=revision&revision=55143: Various Py 3 changes
r59154: Write files in text mode
r53189: Avoid has_key()
http://svn.python.org/view?view=revision&revision=55167: xrange() → range()

----------

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


More information about the Python-bugs-list mailing list