[Python-Dev] Work in progress - coercion/cmp overhaul

Neil Schemenauer nas@arctrix.com
Mon, 13 Nov 2000 00:36:53 -0800

I making this available now in the hope that it will generate
some dicussion:


The patch is based on Marc-Andre Lemburg's coercion patch for
1.5.1 downloaded from the starship:


All credit goes to him.  The bugs are probably introduced by me.
What the patch does:

  - Introduces a new type flag "NEWSYTLENUMBER".  If this flag is
    set then the tp_as_number methods are treated differently.
    Coercion is not done before passing arguments to the method.
    New style methods do their own coercion or return the
    NotImplemented singleton.  See Marc's page for more details.

  - Updates the PyInt, PyFloat and PyInstance types to use new
    style methods.

  - Changes PyNumber_Multiply to only swap arguments if second
    argument implements sq_repeat.


  - It gives extension types more control over how they implement
    number methods.

  - Removes the special handling of PyInstance in abstract.c.

  - Slightly speeds up the interpreter.


  - Clean up cmp() operator and implement rich comparsions for
    the new nb_cmp slot.

  - Decide on handling of nb_coerce slot (eg. should it be called
    on new style numbers).

  - Convert PyComplex and PyLong to use new style.