[ZODB-Dev] Typechecking oid in getitem

Jeremy Hylton jeremy at zope.com
Mon May 19 18:00:19 EDT 2003


On Mon, 2003-05-19 at 12:53, Toby Dickenson wrote:
> On Monday 19 May 2003 5:41 pm, Christian Reis wrote:
> > On Mon, May 19, 2003 at 01:16:26PM -0300, Christian Reis wrote:
> > > Note that many places we already do try: except KeyError, so maybe it
> > > would be a matter of changing KeyError to (KeyError, TypeError) in these
> > > places?
> >
> > How does this look?
> 
> POSKeyError implies "object not found under that oid", not "malformatted oid".
> 
> What about something like
> 
>          try:
>              pos=_index[oid]
>          except KeyError:
>              raise POSKeyError(oid)
> +        except TypeError:
> +            raise TypeError('malformatted oid %r' % (oid,))
> 
> 
> > I can make POSKeyError more beautiful ;) later.
> 
> POSKeyError displays repr(oid), and I cant think of anything better in the 
> general case. Jeremys Long oids will make this nicer.

Good point.  The only reason for POSKeyError is to make the exception
look nicer when it gets printed in a traceback.  So there's no point in
converting a TypeError to POSKeyError.  It does make sense to raise
TypeErro, "invalid oid: %r" % oid

Jeremy





More information about the ZODB-Dev mailing list