can't overrride __and__(), __or__() (and __invert__()?)

Issue #3012 resolved
Mike Bayer repo owner created an issue
from sqlalchemy import Integer, TypeDecorator, Column, type_coerce

class Foo(TypeDecorator):
    impl = Integer

    class comparator_factory(TypeDecorator.Comparator):
        def __eq__(self, other):
            print "EQ!"
            return type_coerce(self.expr, Integer) == other

        def __and__(self, other):
            print "AND!"
            return type_coerce(self.expr, Integer) & other


c = Column('x', Foo())

print c == 5
print c & 2

Comments (2)

  1. Mike Bayer reporter
    • Fixed bug where the :meth:.Operators.__and__, :meth:.Operators.__or__ and :meth:.Operators.__invert__ operator overload methods could not be overridden within a custom :class:.TypeEngine.Comparator implementation. fixes #3012

    → <<cset d1705a46fea6>>

  2. Mike Bayer reporter
    • Fixed bug where the :meth:.Operators.__and__, :meth:.Operators.__or__ and :meth:.Operators.__invert__ operator overload methods could not be overridden within a custom :class:.TypeEngine.Comparator implementation. fixes #3012

    → <<cset 24ca70afd0df>>

  3. Log in to comment