[ZODB-Dev] Typechecking oid in getitem

Tim Peters tim at zope.com
Mon May 19 13:33:25 EDT 2003


[Jeremy Hylton]
> The type of an oid depends on the storage, so there is no guarantee that
> it will be a string.  In fact, ZODB4 storages will soon change to using
> Python longs.  APE uses tuples IIRC.

Just noting that Chris Withers's bafflement when typing "dict(conn)" instead
of "dir(conn)" was also partly due to that

    Connection.__getitem__(integer)

raised an exception deep in the bowels (an "unsubscriptable object" error,
in code trying to treat the int passed to __getitem__ as if it were a
string).

I'm afraid that one would remain hard to understand even if __getitem__
complained early, since the integer was produced by an iterator synthesized
on dict's behalf by iter() (iter() believed Connection is a sequence because
Connection implements __getitem__, and dict() didn't believe Connection is a
mapping because Connection doesn't implement .keys()).  It would have been
easier to understand, though.




More information about the ZODB-Dev mailing list