Message2309
Logged In: YES
user_id=61408
if we eagerly coerce then (at least for instances), for
example changing half_cmp to test:
if (o1.__class__ != o2.__class__ || o1 instanceof
PyInstance
|| o2 instanceof PyInstance) {
the output becomes:
log: [] coerce((),C()): (<__main__.C instance 1>,
<__main__.C instance 2>)
log: ['C_coerce', 'D_eq'] cmp(C(),C()): 0
log: ['D_eq'] cmp(C(),D()): 0
log: ['D_eq'] cmp(D(),C()): 0
log: ['D_eq'] cmp(D(),D()): 0
log: ['C_coerce', 'D_eq'] C()==C(): 1
log: ['D_eq'] C()==D(): 1
log: ['D_eq'] D()==C(): 1
log: ['D_eq'] D()==D(): 1
[yep, also builtin coerce need fixing]
notice the 0 because
return o1._cmp(o2);
tries __eq__.
I'm tempted to go with something like this [not tested]:
int half = this.__cmp__(other)
if (half != -2)
{
return half;
}
if (!(this instanceof PyInstance) {
half = other.__cmp__(this);
if (half != -2)
{
return -half;
}
}
pushing the coercion logic down the PyObject subclasses like
we do for all the other bin ops, and having
PyInstance.__cmp__ doing everything necessary for that case
like instance_compare
in CPython does. I may try this on the newstyle branch.
Thanks. |
|
Date |
User |
Action |
Args |
2008-02-20 17:18:22 | admin | link | issue859555 messages |
2008-02-20 17:18:22 | admin | create | |
|