How to define a bytes literal in Python 2.x for porting to Python 3.x using 2to3?

Terry Reedy tjreedy at udel.edu
Sat Jan 1 17:47:58 EST 2011


On 1/1/2011 5:07 PM, Martin v. Loewis wrote:

 >> I think the developers expected that most maintained and updated 2.x
 >> code, especially code targeted at 3.x also, would be migrated to 2.6+.
 >
 > Unfortunately, that assumption has hurt Python 3 migration
 > significantly. It gave the impression that, as long as you need to
 > support Python 2.5 and earlier, there is no way you could possibly
 > support Python 3 as well, and that, therefore, starting to support
 > Python 3 is pointless for many years to come.
 >
 > I personally never shared that assumption, and encourage people to
 > ignore these gimmicks that had been added to 2.6 to ease porting.
 > Instead, people should first determine what Python versions their
 > users want to see supported, and then look for solutions that cover
 > all these versions.

You have shown that it is easier than some people thought. I think two 
key ideas are these.

1. Code running in multiple versions has to be syntactically correct in 
every detail all versions in order to be compiled without error. 
However, version specific syntax *can* be used in modules that are 
conditionally imported and therefore conditionally compiled and executed.

2. The syntax of function calls has hardly changed and using the common 
subset is no limitation for the overwhelming majority of uses. Moreover, 
function names can be conditionally bound to version-specific function 
objects, whether builtin or imported.

-- 
Terry Jan Reedy




More information about the Python-list mailing list