We took a quick glance at CPython yesterday, and it didn't look like it was
doing anything special to handle this. The exception basically seemed to
just disappear. It would be a simple patch to just make the __nonzero__
function toss out any exception that occurs when searching the Python
classes for __nonzero__. But is that the "right" way?
Kevin
----- Original Message -----
From: "Randy Jay Yarger" <ry...@we...>
To: <jyt...@li...>
Sent: Wednesday, August 29, 2001 4:42 PM
Subject: [Jython-dev] Exception Handling difference between CPython and
Jython
> Howdy,
>
> There appears to be a slight difference in the exception handling
> between CPython and Jython.
> Before I dig into CPython's code I want to see if this is a known problem.
>
> Here is my test case:
> -----------------------------------
> class Foo:
> def __getattr__(self, key):
> print 'getting %s' % key
> raise KeyError, key
>
> foo = Foo()
> if not foo: print 'no foo'
> -------------------------------------
>
> CPython has the following output:
> =========================
> getting __nonzero__
> getting __len__
> =========================
>
> Where Jython does this:
> =========================
> WE: getting __nonzero__
> Traceback (innermost last):
> File "tc.py", line 7, in ?
> File "tc.py", line 4, in __getattr__
> KeyError: __nonzero__
> ==========================
>
> Since _getattr__ always raises an error, it seems the CPython is doing
> something magical under the hood.
>
> Has anyone seen anything similar?
>
> Thanks,
> Randy Jay Yarger (ry...@we...)
> Phabric Development (www.phabric.org) @ Web Elite (www.webelite.com)
>
>
> _______________________________________________
> Jython-dev mailing list
> Jyt...@li...
> http://lists.sourceforge.net/lists/listinfo/jython-dev
|