[Python-Dev] Detecting tp_compare / tp_richcompare from Python
tseaver at palladion.com
Thu Nov 8 17:18:32 CET 2012
-----BEGIN PGP SIGNED MESSAGE-----
While porting the BTrees package (split out from ZODB) to Python3., my
first step is to get the pure-Python reference implementation working:
in order to do that, I need a way to check that objects used as keys are
*not* using the comparison semantics inherited from the base 'object'
class, because those semantics rely on properties which are not stable
across the lifetime of the (persisted / restored) key.
The existing C code does something like::
if (arg->ob_type->tp_richcompare == NULL
&& arg->ob_type->tp_compare ==
PyErr_SetString(PyExc_TypeError, "Object has default comparison");
Unless I'm mistaken, there is no way to do the equivalent from pure
Python.. I tried a couple of approximations which relied on non-API
attributes (I"m looking at out, methodwrapper.__objclass__), but without
much success (and I need the code to work on PyPy / Jython, too).
Am I missing something?
Tres Seaver +1 540-429-0999 tseaver at palladion.com
Palladion Software "Excellence by Design" http://palladion.com
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.11 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://www.enigmail.net/
-----END PGP SIGNATURE-----
More information about the Python-Dev