[Python-Dev] python 3.0, tp_compare not used for == test?
Terry Reedy
tjreedy at udel.edu
Mon Feb 2 07:53:56 CET 2009
Campbell Barton wrote:
> Hi, I have been writing a new C api that can build with both python 2.6 and 3.0
Questions about using current releases should be directed to the
python-list (or comp.lang.python or gmane.comp.python.general), not
python-dev, which is for development of future releases.
> I found that when building with python 2.6, doing "a==b" between 2
> different pyrna_struct_Type's would run tp_compare
>
> But with python 3.0, "a==b" will always be false and tp_compare
> function would not even run.
> The only way to get it to run the tp_compare function was to do
> "cmp(a, b)" however Id like to be able to use == still.
In 3.0, the build-in cmp() should have been removed and will be for
3.0.1. Do not use it. I believe the tp_compare slot should not be used
either. It will become reserved. It will not be removed only because
that would change the binary layout.
So use rich comparisons.
More information about the Python-Dev
mailing list