[Python-porting] Some questions about build_py_2to3

"Martin v. Löwis" martin at v.loewis.de
Tue Dec 9 00:18:32 CET 2008


Thomas Heller wrote:
> I have some beginners questions about distutils build_py_2to3 command:
> 
> - Can it convert doctests?  How?

It only converts what lib2to3 converts - so the question really is
whether lib2to3 can convert doctests. AFAICT, no doctest fixer has been
written yet (although it should be possible to write on - probably on
an opt-in basis).

> - Shouldn't build_py_2to3 use a differnt build directory than the normal
> build_py command?  Perhaps build/lib-3 or something like that?

Perhaps. We would need to check first whether this is feasible to
implement (I don't know off-hand), as install_lib then needs to pick
up the right files. Then, the next question is whether changing the
layout risks compatibility with external tools, such as setuptools.

So for the time being, you have to clean the build directory when you
switch Python versions.

> - Should programming idioms that it fails to convert be reported as bugs?

On a case-by-case basis - yes, they should be reported, as 2to3 bugs.

> Here is one example that isn't converted at all:
> 
>   class CoClass(COMObject):
>       from comtypes._meta import _coclass_meta as __metaclass__
> 
> 
> It is not obvious immeditately how the converted code should look like,
> but at least the converter could issue a warning.

I don't think this can reasonably converted; you should rewrite it
first. This is typical - IMO, it is a true bug in 2to3 ONLY IF there
is no way to write it in 2.x so that 2to3 will convert it correctly.
If you can rewrite it by hand, then it is only a feature request for
2to3.

Channeling Guido (thereby moving to thin ice): It is a bug only if
python 2.6 -3 will not issue a warning, 2to3 does nothing, yet it
fails to run in 3.x. The bug then might be in -3 (for not issuing
a warning), or in 2to3 (for not converting), or in 3.x
(for rejecting).

In the specific case, it is easy to rewrite so that 2to3 can handle
it properly:

from comtypes._meta import _coclass_meta
class CoClass(COMObject):
   __metaclass__ = _coclass_meta
   ...
del _coclass_meta

Whether or not warnings should be issued is a different question.
Not sure whether 2to3 already issues warnings in some cases, and,
if it does, whether build_py_2to3 displays them.

Regards,
Martin


More information about the Python-porting mailing list