[Python-porting] Port of psycopg2

M.-A. Lemburg mal at egenix.com
Mon Dec 15 20:55:49 CET 2008


On 2008-12-13 00:13, Martin v. Löwis wrote:
>> The problem with this approach is that 2to3 is a fast moving target
>> and relying on the version that comes with Python is likely not going
>> to work out if you need a more recent version of 2to3 for your code.
> 
> So program against the version that comes with Python. I found that this
> works quite well.
>
> Of course, it worked best when you reported all problems you have in
> your software before 3.0 was released.

In an ideal world that would have happened, but in the real world
Python 2.x development is still what pays the bill.

>> For source distributions this either means that you have to ship
>> 2to3 with your code or that you ship already converted code.
>>
>> BTW: Is it possible to extend 2to3 with your own fixers dynamically,
>> e.g. to work around this problem ?
> 
> Sure. You can pass explicit lists of fixers.

Can I register new ones somewhere ? (other than copying them into the
fixes package dir or monkey patching them in there)

>> Is there an overview of how lib2to3 works somewhere ?
> 
> How top-level do you want the overview to be? There is the fixes
> directory, with one module per fixer. lib2to3 imports them all,
> and then runs them one after another.

Well, I know about the http://docs.python.org/library/2to3.htm page
and can read the source code, but I'm missing an overview of the
fixers API and the pattern definition language used in them.

The API looks rather complicated, even for very simple search and
replace tasks such as __nonzero__ -> __bool__ conversion, e.g. from
fix_nonzero.py:

class FixNonzero(fixer_base.BaseFix):
    PATTERN = """
    classdef< 'class' any+ ':'
              suite< any*
                     funcdef< 'def' name='__nonzero__'
                              parameters< '(' NAME ')' > any+ >
                     any* > >
    """

    def transform(self, node, results):
        name = results["name"]
        new = Name("__bool__", prefix=name.get_prefix())
        name.replace(new)

PATTERN looks like some kind of tree pattern recognition language.
I would assume that node is the found node, but have no idea
what results means. prefix also is a mystery - method names don't
have prefixes, so this has got to be something else.

-- 
Marc-Andre Lemburg
eGenix.com

Professional Python Services directly from the Source  (#1, Dec 15 2008)
>>> Python/Zope Consulting and Support ...        http://www.egenix.com/
>>> mxODBC.Zope.Database.Adapter ...             http://zope.egenix.com/
>>> mxODBC, mxDateTime, mxTextTools ...        http://python.egenix.com/
________________________________________________________________________
2008-12-02: Released mxODBC.Connect 1.0.0      http://python.egenix.com/

::: Try our new mxODBC.Connect Python Database Interface for free ! ::::


   eGenix.com Software, Skills and Services GmbH  Pastor-Loeh-Str.48
    D-40764 Langenfeld, Germany. CEO Dipl.-Math. Marc-Andre Lemburg
           Registered at Amtsgericht Duesseldorf: HRB 46611
               http://www.egenix.com/company/contact/


More information about the Python-porting mailing list