Martin KellyMon Jul 10 00:01:44 PDT 2006
I reported the bug to Python and apparently it has already been fixed in the latest SVN build... that is good news :). Bob Miller wrote: > Martin Kelly wrote: > >> I'm trying to figure out what error type is given by shelve.open(file, >> "r") when the file does not exist. > > The exception type is an anydbm.error. But I don't understand the > source code. > >>From anydbm.py: > > # ... > class error(Exception): > pass > # ... > error = tuple(_errors) > # ... line 77: > raise error, "need 'c' or 'n'..." > > The Python Reference Manual doesn't say anything about using a tuple > in a raise statement. > > http://docs.python.org/ref/raise.html > > But that's what it is. Here's a sample shell session. > > Python 2.4.3 (#1, Jun 28 2006, 06:34:30) > [GCC 3.4.6 (Gentoo 3.4.6-r1, ssp-3.4.5-1.0, pie-8.7.9)] on linux2 > Type "help", "copyright", "credits" or "license" for more information. > >>> import shelve > >>> import anydbm > >>> try: > ... shelve.open('nonexistent', 'r') > ... except anydbm.error: > ... print 'caught it' > ... > caught it > Exception exceptions.AttributeError: "DbfilenameShelf instance has no > attribute 'writeback'" in ignored > >>> anydbm.error > (<class anydbm.error at 0xb7f48bfc>, > <class bsddb._db.DBError at 0xb7f5623c>, > <class gdbm.error at 0xb7f48cbc>, > <class dbm.error at 0xb7f5b38c>, > <class exceptions.IOError at 0xb7f774ac>) > >>> > > So, uh, what's that weird other bit, exceptions.AttributeError? > That's a bug in Python 2.4.3. You can see in shelve.py that > Shelf.__del__() calls Shelf.close() calls Shelf.sync() which > references self.writeback even though that attribute doesn't exist. > It also references self.dict which also doesn't exist. > > My opinion is that if shelve is that poorly debugged, it's probably > not ready for prime time. > > Or you could submit a bug report... >