py3k concerns. An example

"Martin v. Löwis" martin at v.loewis.de
Mon May 12 15:21:02 EDT 2008


> Well, my concerns about 3.0 continue to be founded.  Up until now I
> have been just reading "What's New" docs, and relying on input from
> others as to what changes I will have to make.  Yesterday I downloaded
> and installed 3.0a5, and it is clear that there is *no* way to have a
> single code base for any but the most trivial module.

I think there is a way, if you can use 2to3.

> The biggest sticking point is the incompatibility of "except" syntax.
> Apparently the promise of syntax compatibility in the 3.0a4 docs was
> an overstatement.  Syntax can't be conditionalized out with "if
> version >= 3:" type code, so I must have separate Python 2.x and
> Python 3.x codebases, as will anyone whose modules include exception
> handlers.

No, you don't need to maintain two code bases. Just maintain the 2.x
one, and generate the 3.x code every time you need it updated.

2to3 deals with the change to the except clauses just fine.

> I also tripped over the conversion from "<iterator>.next()" to
> "next(<iterator>)". 

2to3 should also fix that one. Alternatively, you can add your own
next implementation to 2.x.

> Conversion of print from statement to function is definitely more
> painful than I thought it would be.  Again, I am fortunate that this
> largely affects only my test code, with only minimal impact on my
> runtime module.

Again, 2to3 fixes these just fine.

> I continue to struggle with some of the refactoring done in references
> to func.func_code, im_self, etc. changing to __code__, __self__, and
> so on.

There are also 2to3 fixers for these, although they might be incomplete.

> By the way Martin, your work on 2to3 was especially helpful in this
> effort - thank you!

Thanks - but this is really Collin Winter's work (with various
contributions of others, of course).

> In summary, I am adjusting my plans for future support of Python
> versions in pyparsing.  As of a pyparsing release some time after
> August, I will only support Python 3.0 versions with any new features
> or bugfixes, and the pyparsing version that is compatible with Python
> 2.x will be frozen.

I don't want to interfere with your project plans, but I don't think
there is a factual need for such a process. Instead, you could continue
to write 2.x code, and produce 3.x code either at release or at install
time.

Regards,
Martin



More information about the Python-list mailing list