[ZODB-Dev] dict(conn) produces wierd error in ZODB 3.2
Tim Peters
tim at zope.com
Sun May 18 18:50:58 EDT 2003
[Chris Withers]
> >>> s = FileStorage('e:\\test.fs')
> >>> from ZODB import DB
> >>> db = DB(s)
> >>> conn = db.open()
> >>> dict(conn)
[Dieter Maurer]
> What is "dict"?
Chris was using Python 2.2, and starting in 2.2 most builtin type names can
be used as constructors. This was part of 2.2's type-class unification
work.
>>> print dict.__doc__
dict() -> new empty dictionary.
dict(mapping) -> new dictionary initialized from a mapping object's
(key, value) pairs.
dict(seq) -> new dictionary initialized as if via:
d = {}
for k, v in seq:
d[k] = v
>>>
Trying to pass a Connection object to dict() doesn't make sense.
Unfortunately, Connection implements only the __getitem__ part of the
mapping protocol. Because it doesn't also define .keys(), 2.2 believes that
the existence of Connection.__getitem__ means Connection is actually a
sequence, so treats conn under the "dict(seq)" case of the docs above.
Garbage-in garbage-out is the result.
More information about the ZODB-Dev
mailing list