works with ColumnElement as well as works with non-__eq__() suppliers,
works with sets, on Py3K as well.
def __hash__(self):
return hash(self.__element)
- def __cmp__(self, other):
- return cmp(hash(self.__element), hash(other))
+ def __eq__(self, other):
+ if isinstance(self.__element, expression.ColumnOperators):
+ return self.__element.__class__.__eq__(self, other)
+ else:
+ return hash(other) == hash(self)
+
# hard-generate Annotated subclasses. this technique
# is used instead of on-the-fly types (i.e. type.__new__())
assert not t2.select().alias('foo').is_derived_from(t1)
class AnnotationsTest(fixtures.TestBase):
+
+ def test_hashing(self):
+ t = table('t', column('x'))
+
+ a = t.alias()
+ s = t.select()
+ s2 = a.select()
+
+ for obj in [
+ t,
+ t.c.x,
+ a,
+ s,
+ s2
+ ]:
+ annot = obj._annotate({})
+ eq_(set([obj]), set([annot]))
+
def test_custom_constructions(self):
from sqlalchemy.schema import Column
class MyColumn(Column):