[Python-Dev] converting the stdlib to str.format

Guido van Rossum guido at python.org
Tue Jun 3 04:04:07 CEST 2008


On Mon, Jun 2, 2008 at 5:49 PM, Benjamin Peterson
<musiccomposition at gmail.com> wrote:
> As a newly converted fan of str.format, it gives me pangs to see the
> whole stdlib using "%." I realize that str.format is not quite up to
> the speed standards we'd like, but I'm sure that will change.
>
> In any case, I'm willing to give the TLC to convert the whole stdlib
> to str.format, so I just need your permission! <wink>

So glad you asked! There's a standard answer whenever someone suggests
a sweeping conversion of the entire stdlib to some new feature. It's
"No." :-)

In the past, we've tried things like this a few times, and it was
nearly always a mistake. Things like this can't be automated 100%, and
doing a manual audit of the changes is so incredibly tedious that
inevitably a few incorrect changes slip by.

In theory these would be caught by unittests, but in practice the
difference between practice and theory is larger than in theory, so
inevitably the honor falls to some poor schmuck whose application
fails in a non-trivial way, often months later. I recall one
particularly ill-fated conversion where we some bogus conversions
weren't fixed until several years (and releases!) later. And these
were pretty badly botched too, something like foo(bar(x, y)) vs.
foo(bar(x), y) -- it was just in rarely executed code and due to the
complexity of the expressions (and the fact that the parentheses were
balanced ;-) nobody had noticed before.

It's much better to do this piecemeal, when you are revising a
particular module for some other reason. Then you (presumably) have
the time to review every change thoroughly -- and hopefully you can
even add unittests for all code you touch.

I realize that 2to3 might make such conversions less error-prone. But
most 2to3 conversions are not 100% correct either, and the problem of
falling asleep while reviewing the changes exists especially where
there are so many correct conversions!

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


More information about the Python-Dev mailing list