[Python-Dev] New/Old class exception pitfall
Alexander Belopolsky
alexander.belopolsky at gmail.com
Tue Mar 18 00:29:54 CET 2008
Oleg Broytmann <phd <at> phd.pp.ru> writes:
>
> On Mon, Mar 17, 2008 at 06:35:46PM -0400, Alexander Belopolsky wrote:
> > class x:
> > pass
> > class y(x):
> > pass
> > try:
> > raise y
> > except y:
> > print "a"
> > except:
> > print "b"
> >
> > It prints 'b'.
>
> Python 2.2, 2.3, 2.4 and 2.5 on Linux: prints 'a'.
>
Sorry, my fault. It prints 'a' without __metaclass__ = type,
but prints 'b' with the metaclass. The output should be the
same in both cases.
The problematic case is:
__metaclass__ = type
class x:
pass
class y(x):
pass
try:
raise y
except y:
print "a"
except:
print "b"
the above code prints 'b' in 2.x
More information about the Python-Dev
mailing list