From 2480f587e1c3ae188a3be045584434f3fc49ddf4 Mon Sep 17 00:00:00 2001 From: Daniele Varrazzo Date: Mon, 1 Nov 2010 23:10:20 +0000 Subject: [PATCH] Added warning note about equivalence inconsistence between Notify and tuples. --- psycopg/notify_type.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/psycopg/notify_type.c b/psycopg/notify_type.c index 8f39da1e..53969709 100644 --- a/psycopg/notify_type.c +++ b/psycopg/notify_type.c @@ -147,6 +147,24 @@ notify_astuple(NotifyObject *self, int with_payload) return tself; } +/* note on Notify-tuple comparison. + * + * Such a comparison is required otherwise a check n == (pid, channel) + * would fail. We also want to compare two notifies, and the obvious meaning is + * "check that all the attributes are equal". Unfortunately this leads to an + * inconsistent situation: + * Notify(pid, channel, payload1) + * == (pid, channel) + * == Notify(pid, channel, payload2) + * even when payload1 != payload2. We can probably live with that, but hashing + * makes things worse: hashability is a desirable property for a Notify, and + * to maintain compatibility we should put a notify object in the same bucket + * of a 2-item tuples... but we can't put all the payloads with the same + * (pid, channel) in the same bucket: it would be an extremely poor hash. + * So we maintain compatibility in the sense that notify without payload + * behave as 2-item tuples in term of hashability, but if a payload is present + * the (pid, channel) pair is no more equivalent as dict key to the Notify. + */ static PyObject * notify_richcompare(NotifyObject *self, PyObject *other, int op) {