[Python-3000] Looking for advice on PEP 3101 implementation details

Guido van Rossum guido at python.org
Tue Aug 21 03:00:55 CEST 2007


On 8/20/07, Eric Smith <eric+python-dev at trueblade.com> wrote:
> I'm basically done with format(), string.format(), object.__format__(),
> string.__format__(), long.__format__(), and float.__format__().  I have
> some cleanup left to do from all of the refactoring, but it's passing
> the vast majority of my tests.
>
> The only real remaining work is to implement string.Formatter.  This is
> a class designed to be overridden to customize the formatting behavior.
>   It will share much of the C code with string.format().
>
> My plan is to write this class in Python, and put it in Lib/string.py.
> Given the complexities and book-keeping involved, writing it in C
> doesn't seem worth the hassle.  In order to talk back to the C
> implementation code, I'll create a private module in Modules/_formatter.c.
>
> Does this seem reasonable?

Sure.

> If so, my question is how to add module in the Modules directory.  There
> is some logic in the top level Makefile.pre.in, but it doesn't look like
> it applies to all of the code in Modules, just some of the files.
>
> Modules/Setup.dist contains this comment:
> # This only contains the minimal set of modules required to run the
> # setup.py script in the root of the Python source tree.
>
> I think this applies to me, as setup.py indirectly includes string.
>
> So, is the right thing to do to insert my _formatter.c into
> Modules/Setup.dist?  Is there anything else I need to do?  Is there some
> existing code in Modules that I should base my approach on?
>
> I googled for help on this, but didn't get anywhere.
>
> Thanks again for your assistance.

You can ignore Makefile* and Modules/Setup*; instead, you should be
editing setup.py at the toplevel. Since your new module doesn't depend
on anything external it should be a one-line change, modeled after
this one:

exts.append( Extension('_weakref', ['_weakref.c']) )

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list