[Python-3000] PEP 3002 (Procedure for Backwards-Incompatible Changes)

Steven Bethard steven.bethard at gmail.com
Mon May 8 04:23:09 CEST 2006


On 5/1/06, Guido van Rossum <guido at python.org> wrote:
> On 4/29/06, Steven Bethard <steven.bethard at gmail.com> wrote:
> > Yes, I think it definitely makes more sense to make the modifications
> > on 2.x.  I was hesitant to require integrating it into the main-line
> > Python 2.x code because I was worried about affecting performance.
> > But of course with a command-line flag, that point is moot.  So
> > basically python3warn.py could be become "python -SOME_OPTION" where
> > SOME_OPTION would enable all the Python 3.0 checks.
> >
> > So I guess the question then is what the option should enable.  Should
> > it try to implement the Python 3.0 behavior?  Or should it just warn
> > when the behavior is changed?  The former requires much more Python
> > 3.0 code to be back-ported to Python 2.X, but would presumably give
> > much better error reporting.  I'd love to require that, but I'm afraid
> > of the work it would take.
>
> It should continue to use the 2.x semantics to the greatest extent
> possible, while issueing warnings about any constructs whose semantics
> will change in 3.0.
>
> I have a fairly elaborate example in mind: with this new flag,
> dict.keys() should return a subclass of list which behaves exactly
> like list except that it issues a warning whenever you use any method
> other than __iter__(). This should be transparent except to the most
> demanding code (the subclass could theoretically cause programs to
> behave differently but in practice I doubt it will change much) and
> should catch any code that uses the result of keys() other than to
> loop over it; at the same time it will not complain about code that
> simply assigns keys() to a variable and later (perhaps in a different
> function) loops over that variable.

Sorry this took so long, but I've finally updated the PEP (stealing
your example above) so that it requires patches to the Python 2.X
repository.  From the updated PEP:

Identifying Problematic Code
============================

In addition to the PEP requirement, backwards incompatible changes to
Python must also be accompanied by code to issue warnings for pieces
of Python 2.X code that will behave differently in Python 3000. Such
warnings will be enabled in Python 2.X using a new command-line
switch: --python3. All backwards incompatible changes should be
accompanied by a patch for Python 2.X that, when --python3 is
specified, issues warnings for each construct that is being changed.

For example, if ``dict.keys()`` returns an iterator in Python 3000,
the patch to the Python 2.X branch should do something like:

    If --python3 was specified, change ``dict.keys()`` to return a
    subclass of ``list`` that issues warnings whenever you use any
    methods other than ``__iter__()``.

Such a patch would mean that warnings are only issued when features
that will not be present in Python 3000 are used, and almost all
existing code should continue to work. (Code that relies on
``dict.keys()`` always returning a ``list`` and not a subclass should
be pretty much non-existent.)


STeVe
--
Grammar am for people who can't think for myself.
        --- Bucky Katt, Get Fuzzy


More information about the Python-3000 mailing list