[Python-3000] PEP 3113 transition plan

Collin Winter collinw at gmail.com
Wed Mar 7 01:43:35 CET 2007


>From the checked-in version,

"""
Two additional transformations will be added to the 2to3 translation tool [3]:

    * Method definitions named next will be renamed to __next__.
    * Explicit calls to the next method will be replaced with calls to
the built-in next function. For example, x.next() will become next(x).

If the module being processed already contains a binding for the name
next, the second transformation will not be done; instead, calls to
x.next() will be replaced with x.__next__() and a warning will be
emitted. (Collin Winter has looked into this [4] and found that it's
difficult to make the second transformation depend on the presence of
a module-level binding; warning about the existence of bindings to
next should be possible, though.)
"""

I'd like to strike the part about making "x.next()" ->
"next(x)"/"x.__next__()" determined by the presence of a module-level
"next" binding. I'd rather see the transformation always be "x.next()"
-> "next(x)" and warn on top-level "next"s. Doing it the way the PEP
suggests is possible, but ugly (requires an unusually-complicated
fixer) and slow. I can give you warnings on the following items,
though:

- global assignments to "next".
- global definitions of a "next" function.
- global imports of anything named "next".
- assignments to "__builtin__.next".

Will that do?

Collin Winter


More information about the Python-3000 mailing list