[ZODB-Dev] Persistent breaks __contains__?

William hb2vnlu02 at sneakemail.com
Mon Feb 9 19:03:57 EST 2004


Hi.  I'm new to ZODB, and the following baffles me.

        Python 2.3.3 (#2, Jan 13 2004, 00:47:05)
        [GCC 3.3.3 20040110 (prerelease) (Debian)] on linux2
        Type "help", "copyright", "credits" or "license" for more information.
        >>> import ZODB
        >>> class Foo:
        ...     def __contains__(self, key):
        ...             return True
        ...
        >>> class Bar(ZODB.Persistent):
        ...     def __contains__(self, key):
        ...             return True
        ...
        >>> 2 in Foo()
        True
        >>> 2 in Bar()
        Traceback (most recent call last):
          File "<stdin>", line 1, in ?
        AttributeError: __getitem__
        >>> Bar().__contains__(2)
        True
        
Why isn't Bar.__contains__ called by "2 in Bar()"?

William





More information about the ZODB-Dev mailing list