During the course of implementing the Unicode proposal we discussed here in early December I stumbled into an old problem which has caused me some troubles already in the early stages of writing mx.DateTime:
Most of the C slot functions are not capable of dealing with mixed type arguments. Even worse, most expect to be passed "their" type of arguments without even checking them. In Python things are much better: you have the __r***___ methods, can do mixed type arguments, etc.
In short: we need the same things for the C level !
To start this discussion, I would like to point you to an old patch I wrote for Python 1.5. It focusses mainly on the numeric slots, but does provide some insights into possible ways out of the current problems with C level coercions (the business of dealing with mixed type argument):
Here are some starters for the discussion. I think we need:
· slots which are able to deal with mixed type argument
· slots which do not expect to find a certain type without checking for it
· coercion implemented at two levels: 1. a generic mixed type abstract operation mechanism (such as the one included in the above patch for numeric types) 2. slots which can handle mixed type argument and have a way to signal "I can't handle this type combination" (the patch uses a special singleton for this instead of exceptions because the latter cause too much of a perfomance hit -- yes I've tested this).
· all of the above for the numeric slots as well as most of the other slots dealing with PyObject* arguments
Note that these things are also needed for David Ascher's rich comparisons.