Index: Lib/test/test_descr.py =================================================================== --- Lib/test/test_descr.py (revision 3142) +++ Lib/test/test_descr.py (working copy) @@ -479,6 +479,18 @@ pass else: raise TestFailed, "should have raised OverflowError" + try: + foo = int(None) + except TypeError: + pass + else: + raise TestFailed, "should have raised TypeError" + try: + foo = C(None) + except TypeError: + pass + else: + raise TestFailed, "should have raised TypeError" def longs(): if verbose: print "Testing long operations..." Index: src/org/python/core/PyInteger.java =================================================================== --- src/org/python/core/PyInteger.java (revision 3142) +++ src/org/python/core/PyInteger.java (working copy) @@ -687,7 +687,14 @@ if (x instanceof PyBoolean) { return (coerce(x) == 0) ? Py.Zero : Py.One; } - return x.__int__(); + try { + return x.__int__(); + } + catch (PyException pye) { + if (!Py.matchException(pye, Py.AttributeError)) + throw pye; + throw Py.TypeError("int() argument must be a string or a number"); + } } if (!(x instanceof PyString)) { throw Py @@ -699,7 +706,15 @@ return new PyIntegerDerived(subtype, 0); } if (base == -909) { - PyObject intOrLong = x.__int__(); + PyObject intOrLong; + try { + intOrLong = x.__int__(); + } + catch (PyException pye) { + if (!Py.matchException(pye, Py.AttributeError)) + throw pye; + throw Py.TypeError("int() argument must be a string or a number"); + } if (intOrLong instanceof PyInteger) { return new PyIntegerDerived(subtype, ((PyInteger)intOrLong).getValue()); }