[Python-Dev] Work in progress - coercion/cmp overhaul
Neil Schemenauer
nas@arctrix.com
Wed, 15 Nov 2000 09:35:59 -0800
[The python-dev list server seems to have gotten hungry and eaten my
original message. I'm trying again.]
I making this available now in the hope that it will generate
some dicussion:
http://arctrix.com/nas/python/coerce-2.diff
The patch is based on Marc-Andre Lemburg's coercion patch for
1.5.1 downloaded from the starship:
http://starship.python.net/~lemburg/CoercionProposal.html
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.
Why:
- 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.
Todo:
- 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.
Comments?
Neil