Index: Lib/traceback.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/traceback.py,v
retrieving revision 1.30
diff -c -r1.30 traceback.py
*** Lib/traceback.py	18 Jan 2004 20:29:54 -0000	1.30
--- Lib/traceback.py	5 Aug 2004 13:01:36 -0000
***************
*** 155,161 ****
      which exception occurred is the always last string in the list.
      """
      list = []
!     if type(etype) == types.ClassType:
          stype = etype.__name__
      else:
          stype = etype
--- 155,161 ----
      which exception occurred is the always last string in the list.
      """
      list = []
!     if isinstance(etype, type):
          stype = etype.__name__
      else:
          stype = etype
Index: Lib/warnings.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/warnings.py,v
retrieving revision 1.23
diff -c -r1.23 warnings.py
*** Lib/warnings.py	21 Mar 2004 17:06:20 -0000	1.23
--- Lib/warnings.py	5 Aug 2004 13:01:36 -0000
***************
*** 141,147 ****
      assert action in ("error", "ignore", "always", "default", "module",
                        "once"), "invalid action: %r" % (action,)
      assert isinstance(message, basestring), "message must be a string"
!     assert isinstance(category, types.ClassType), "category must be a class"
      assert issubclass(category, Warning), "category must be a Warning subclass"
      assert isinstance(module, basestring), "module must be a string"
      assert isinstance(lineno, int) and lineno >= 0, \
--- 141,147 ----
      assert action in ("error", "ignore", "always", "default", "module",
                        "once"), "invalid action: %r" % (action,)
      assert isinstance(message, basestring), "message must be a string"
!     assert isinstance(category, type), "category must be a class"
      assert issubclass(category, Warning), "category must be a Warning subclass"
      assert isinstance(module, basestring), "module must be a string"
      assert isinstance(lineno, int) and lineno >= 0, \
Index: Lib/test/test_descr.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_descr.py,v
retrieving revision 1.201
diff -c -r1.201 test_descr.py
*** Lib/test/test_descr.py	25 Mar 2004 02:19:34 -0000	1.201
--- Lib/test/test_descr.py	5 Aug 2004 13:01:39 -0000
***************
*** 4054,4060 ****
      funnynew()
      imulbug()
      docdescriptor()
!     string_exceptions()
      copy_setstate()
      slices()
      subtype_resurrection()
--- 4054,4060 ----
      funnynew()
      imulbug()
      docdescriptor()
! ##     string_exceptions()
      copy_setstate()
      slices()
      subtype_resurrection()
Index: Lib/test/test_exceptions.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_exceptions.py,v
retrieving revision 1.19
diff -c -r1.19 test_exceptions.py
*** Lib/test/test_exceptions.py	10 May 2003 07:36:55 -0000	1.19
--- Lib/test/test_exceptions.py	5 Aug 2004 13:01:39 -0000
***************
*** 29,35 ****
  
  def r(thing):
      test_raise_catch(thing)
!     if isinstance(thing, ClassType):
          print thing.__name__
      else:
          print thing
--- 29,35 ----
  
  def r(thing):
      test_raise_catch(thing)
!     if isinstance(thing, type):
          print thing.__name__
      else:
          print thing
***************
*** 173,179 ****
  # test that setting an exception at the C level works even if the
  # exception object can't be constructed.
  
! class BadException:
      def __init__(self):
          raise RuntimeError, "can't instantiate BadException"
  
--- 173,179 ----
  # test that setting an exception at the C level works even if the
  # exception object can't be constructed.
  
! class BadException(Exception):
      def __init__(self):
          raise RuntimeError, "can't instantiate BadException"
  
Index: Lib/test/test_opcodes.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_opcodes.py,v
retrieving revision 1.12
diff -c -r1.12 test_opcodes.py
*** Lib/test/test_opcodes.py	30 Jul 2002 23:27:11 -0000	1.12
--- Lib/test/test_opcodes.py	5 Aug 2004 13:01:39 -0000
***************
*** 25,33 ****
  
  print '2.2 raise class exceptions'
  
! class AClass: pass
  class BClass(AClass): pass
! class CClass: pass
  class DClass(AClass):
      def __init__(self, ignore):
          pass
--- 25,35 ----
  
  print '2.2 raise class exceptions'
  
! class AClass(Exception):
!     def __init__(self):
!         pass
  class BClass(AClass): pass
! class CClass(Exception): pass
  class DClass(AClass):
      def __init__(self, ignore):
          pass
Index: Lib/test/test_richcmp.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_richcmp.py,v
retrieving revision 1.10
diff -c -r1.10 test_richcmp.py
*** Lib/test/test_richcmp.py	28 Oct 2003 12:05:47 -0000	1.10
--- Lib/test/test_richcmp.py	5 Aug 2004 13:01:39 -0000
***************
*** 211,217 ****
          # Check that exceptions in __nonzero__ are properly
          # propagated by the not operator
          import operator
!         class Exc:
              pass
          class Bad:
              def __nonzero__(self):
--- 211,217 ----
          # Check that exceptions in __nonzero__ are properly
          # propagated by the not operator
          import operator
!         class Exc(Exception):
              pass
          class Bad:
              def __nonzero__(self):
***************
*** 305,311 ****
      def test_badentry(self):
          # make sure that exceptions for item comparison are properly
          # propagated in list comparisons
!         class Exc:
              pass
          class Bad:
              def __eq__(self, other):
--- 305,311 ----
      def test_badentry(self):
          # make sure that exceptions for item comparison are properly
          # propagated in list comparisons
!         class Exc(Exception):
              pass
          class Bad:
              def __eq__(self, other):
Index: Lib/test/test_signal.py
===================================================================
RCS file: /cvsroot/python/python/dist/src/Lib/test/test_signal.py,v
retrieving revision 1.15
diff -c -r1.15 test_signal.py
*** Lib/test/test_signal.py	11 Jun 2004 18:09:28 -0000	1.15
--- Lib/test/test_signal.py	5 Aug 2004 13:01:39 -0000
***************
*** 29,40 ****
      if verbose:
          print "handlerA", args
  
! HandlerBCalled = "HandlerBCalled"       # Exception
  
  def handlerB(*args):
      if verbose:
          print "handlerB", args
!     raise HandlerBCalled, args
  
  signal.alarm(20)                        # Entire test lasts at most 20 sec.
  hup = signal.signal(signal.SIGHUP, handlerA)
--- 29,41 ----
      if verbose:
          print "handlerA", args
  
! class HandlerBCalled(Exception):
!     pass
  
  def handlerB(*args):
      if verbose:
          print "handlerB", args
!     raise HandlerBCalled(args)
  
  signal.alarm(20)                        # Entire test lasts at most 20 sec.
  hup = signal.signal(signal.SIGHUP, handlerA)
Index: Objects/typeobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/typeobject.c,v
retrieving revision 2.262
diff -c -r2.262 typeobject.c
*** Objects/typeobject.c	3 Aug 2004 10:21:02 -0000	2.262
--- Objects/typeobject.c	5 Aug 2004 13:01:46 -0000
***************
*** 407,412 ****
--- 407,444 ----
  }
  
  static PyObject *
+ type_str(PyTypeObject *type)
+ {
+ 	PyObject *mod, *name, *rtn;
+ 
+ 	if (!PyType_IsSubtype(type, (PyTypeObject*)PyExc_Exception))
+ 		return type_repr(type);
+ 
+ 	mod = type_module(type, NULL);
+ 	if (mod == NULL)
+ 		PyErr_Clear();
+ 	else if (!PyString_Check(mod)) {
+ 		Py_DECREF(mod);
+ 		mod = NULL;
+ 	}
+ 	name = type_name(type, NULL);
+ 	if (name == NULL)
+ 		return NULL;
+ 
+ 	if (mod != NULL && strcmp(PyString_AS_STRING(mod), "__builtin__")) {
+ 		rtn = PyString_FromFormat("%s.%s",
+ 					  PyString_AS_STRING(mod),
+ 					  PyString_AS_STRING(name));
+ 	}
+ 	else
+ 		rtn = PyString_FromFormat("%s", type->tp_name);
+ 
+ 	Py_XDECREF(mod);
+ 	Py_DECREF(name);
+ 	return rtn;
+ }
+ 
+ static PyObject *
  type_call(PyTypeObject *type, PyObject *args, PyObject *kwds)
  {
  	PyObject *obj;
***************
*** 2260,2266 ****
  	0,					/* tp_as_mapping */
  	(hashfunc)_Py_HashPointer,		/* tp_hash */
  	(ternaryfunc)type_call,			/* tp_call */
! 	0,					/* tp_str */
  	(getattrofunc)type_getattro,		/* tp_getattro */
  	(setattrofunc)type_setattro,		/* tp_setattro */
  	0,					/* tp_as_buffer */
--- 2292,2298 ----
  	0,					/* tp_as_mapping */
  	(hashfunc)_Py_HashPointer,		/* tp_hash */
  	(ternaryfunc)type_call,			/* tp_call */
! 	(reprfunc)type_str,			/* tp_str */
  	(getattrofunc)type_getattro,		/* tp_getattro */
  	(setattrofunc)type_setattro,		/* tp_setattro */
  	0,					/* tp_as_buffer */
Index: Python/ceval.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/ceval.c,v
retrieving revision 2.412
diff -c -r2.412 ceval.c
*** Python/ceval.c	2 Aug 2004 14:50:43 -0000	2.412
--- Python/ceval.c	5 Aug 2004 13:01:47 -0000
***************
*** 1612,1618 ****
  				    why == WHY_CONTINUE)
  					retval = POP();
  			}
! 			else if (PyClass_Check(v) || PyString_Check(v)) {
  				w = POP();
  				u = POP();
  				PyErr_Restore(v, w, u);
--- 1612,1618 ----
  				    why == WHY_CONTINUE)
  					retval = POP();
  			}
! 			else if (PyType_Check(v) || PyString_Check(v)) {
  				w = POP();
  				u = POP();
  				PyErr_Restore(v, w, u);
***************
*** 2925,2934 ****
  		PyErr_Warn(PyExc_PendingDeprecationWarning,
  			   "raising a string exception is deprecated");
  
! 	else if (PyClass_Check(type))
  		PyErr_NormalizeException(&type, &value, &tb);
! 
! 	else if (PyInstance_Check(type)) {
  		/* Raising an instance.  The value should be a dummy. */
  		if (value != Py_None) {
  			PyErr_SetString(PyExc_TypeError,
--- 2925,2933 ----
  		PyErr_Warn(PyExc_PendingDeprecationWarning,
  			   "raising a string exception is deprecated");
  
! 	else if (PyType_Check(type))
  		PyErr_NormalizeException(&type, &value, &tb);
! 	else {
  		/* Raising an instance.  The value should be a dummy. */
  		if (value != Py_None) {
  			PyErr_SetString(PyExc_TypeError,
***************
*** 2939,2957 ****
  			/* Normalize to raise <class>, <instance> */
  			Py_DECREF(value);
  			value = type;
! 			type = (PyObject*) ((PyInstanceObject*)type)->in_class;
  			Py_INCREF(type);
  		}
  	}
- 	else {
- 		/* Not something you can raise.  You get an exception
- 		   anyway, just not what you specified :-) */
- 		PyErr_Format(PyExc_TypeError,
- 			     "exceptions must be classes, instances, or "
- 			     "strings (deprecated), not %s",
- 			     type->ob_type->tp_name);
- 		goto raise_error;
- 	}
  	PyErr_Restore(type, value, tb);
  	if (tb == NULL)
  		return WHY_EXCEPTION;
--- 2938,2947 ----
  			/* Normalize to raise <class>, <instance> */
  			Py_DECREF(value);
  			value = type;
! 			type = (PyObject*)type->ob_type;
  			Py_INCREF(type);
  		}
  	}
  	PyErr_Restore(type, value, tb);
  	if (tb == NULL)
  		return WHY_EXCEPTION;
Index: Python/codecs.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/codecs.c,v
retrieving revision 2.24
diff -c -r2.24 codecs.c
*** Python/codecs.c	8 Jul 2004 01:55:58 -0000	2.24
--- Python/codecs.c	5 Aug 2004 13:01:47 -0000
***************
*** 448,456 ****
  
  PyObject *PyCodec_StrictErrors(PyObject *exc)
  {
!     if (PyInstance_Check(exc))
! 	PyErr_SetObject((PyObject*)((PyInstanceObject*)exc)->in_class,
! 	    exc);
      else
  	PyErr_SetString(PyExc_TypeError, "codec must pass exception instance");
      return NULL;
--- 448,455 ----
  
  PyObject *PyCodec_StrictErrors(PyObject *exc)
  {
!     if (PyType_IsSubtype(exc->ob_type, (PyTypeObject*)PyExc_Exception))
!         PyErr_SetObject((PyObject*)(exc->ob_type), exc);
      else
  	PyErr_SetString(PyExc_TypeError, "codec must pass exception instance");
      return NULL;
Index: Python/errors.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/errors.c,v
retrieving revision 2.82
diff -c -r2.82 errors.c
*** Python/errors.c	24 Mar 2004 22:22:11 -0000	2.82
--- Python/errors.c	5 Aug 2004 13:01:47 -0000
***************
*** 96,106 ****
  		return 0;
  	}
  	/* err might be an instance, so check its class. */
! 	if (PyInstance_Check(err))
! 		err = (PyObject*)((PyInstanceObject*)err)->in_class;
  
! 	if (PyClass_Check(err) && PyClass_Check(exc))
! 		return PyClass_IsSubclass(err, exc);
  
  	return err == exc;
  }
--- 96,107 ----
  		return 0;
  	}
  	/* err might be an instance, so check its class. */
! 	if (!PyType_Check(err))
! 		err = (PyObject*)err->ob_type;
  
! 	if (PyType_Check(err) && PyType_Check(exc))
! 		return PyType_IsSubtype((PyTypeObject*)err, 
! 					(PyTypeObject*)exc);
  
  	return err == exc;
  }
***************
*** 137,155 ****
  		Py_INCREF(value);
  	}
  
! 	if (PyInstance_Check(value))
! 		inclass = (PyObject*)((PyInstanceObject*)value)->in_class;
  
  	/* Normalize the exception so that if the type is a class, the
  	   value will be an instance.
  	*/
! 	if (PyClass_Check(type)) {
  		/* if the value was not an instance, or is not an instance
  		   whose class is (or is derived from) type, then use the
  		   value as an argument to instantiation of the type
  		   class.
  		*/
! 		if (!inclass || !PyClass_IsSubclass(inclass, type)) {
  			PyObject *args, *res;
  
  			if (value == Py_None)
--- 138,157 ----
  		Py_INCREF(value);
  	}
  
! 	if (!PyType_Check(value))
! 		inclass = (PyObject*)value->ob_type;
  
  	/* Normalize the exception so that if the type is a class, the
  	   value will be an instance.
  	*/
! 	if (PyType_Check(type)) {
  		/* if the value was not an instance, or is not an instance
  		   whose class is (or is derived from) type, then use the
  		   value as an argument to instantiation of the type
  		   class.
  		*/
! 		if (!inclass || !PyType_IsSubtype(
! 			    (PyTypeObject*)inclass, (PyTypeObject*)type)) {
  			PyObject *args, *res;
  
  			if (value == Py_None)
***************
*** 527,532 ****
--- 529,535 ----
  	PyObject *mydict = NULL;
  	PyObject *bases = NULL;
  	PyObject *result = NULL;
+ 	PyObject *argstuple;
  	dot = strrchr(name, '.');
  	if (dot == NULL) {
  		PyErr_SetString(PyExc_SystemError,
***************
*** 535,544 ****
  	}
  	if (base == NULL)
  		base = PyExc_Exception;
- 	if (!PyClass_Check(base)) {
- 		/* Must be using string-based standard exceptions (-X) */
- 		return PyString_FromString(name);
- 	}
  	if (dict == NULL) {
  		dict = mydict = PyDict_New();
  		if (dict == NULL)
--- 538,543 ----
***************
*** 557,568 ****
  	bases = PyTuple_Pack(1, base);
  	if (bases == NULL)
  		goto failure;
! 	result = PyClass_New(bases, dict, classname);
    failure:
  	Py_XDECREF(bases);
  	Py_XDECREF(mydict);
  	Py_XDECREF(classname);
  	Py_XDECREF(modulename);
  	return result;
  }
  
--- 556,571 ----
  	bases = PyTuple_Pack(1, base);
  	if (bases == NULL)
  		goto failure;
! 	argstuple = PyTuple_Pack(3, classname, bases, dict);
! 	if (argstuple == NULL)
! 		goto failure;
! 	result = PyType_Type.tp_new(&PyType_Type, argstuple, NULL);
    failure:
  	Py_XDECREF(bases);
  	Py_XDECREF(mydict);
  	Py_XDECREF(classname);
  	Py_XDECREF(modulename);
+ 	Py_XDECREF(argstuple);
  	return result;
  }
  
Index: Python/exceptions.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/exceptions.c,v
retrieving revision 1.48
diff -c -r1.48 exceptions.c
*** Python/exceptions.c	12 Oct 2003 19:09:37 -0000	1.48
--- Python/exceptions.c	5 Aug 2004 13:01:48 -0000
***************
*** 124,130 ****
  
  /* Helper function for populating a dictionary with method wrappers. */
  static int
! populate_methods(PyObject *klass, PyObject *dict, PyMethodDef *methods)
  {
      PyObject *module;
      int status = -1;
--- 124,130 ----
  
  /* Helper function for populating a dictionary with method wrappers. */
  static int
! populate_methods(PyObject *klass, PyMethodDef *methods)
  {
      PyObject *module;
      int status = -1;
***************
*** 150,156 ****
  	}
  
  	/* add method to dictionary */
! 	status = PyDict_SetItemString(dict, methods->ml_name, meth);
  	Py_DECREF(meth);
  	Py_DECREF(func);
  
--- 150,156 ----
  	}
  
  	/* add method to dictionary */
! 	status = PyObject_SetAttrString(klass, methods->ml_name, meth);
  	Py_DECREF(meth);
  	Py_DECREF(func);
  
***************
*** 195,201 ****
      if (!(*klass = PyErr_NewException(name, base, dict)))
  	goto finally;
  
!     if (populate_methods(*klass, dict, methods)) {
  	Py_DECREF(*klass);
  	*klass = NULL;
  	goto finally;
--- 195,201 ----
      if (!(*klass = PyErr_NewException(name, base, dict)))
  	goto finally;
  
!     if (populate_methods(*klass, methods)) {
  	Py_DECREF(*klass);
  	*klass = NULL;
  	goto finally;
***************
*** 345,350 ****
--- 345,352 ----
      PyObject *dict = PyDict_New();
      PyObject *str = NULL;
      PyObject *name = NULL;
+     PyObject *emptytuple = NULL;
+     PyObject *argstuple = NULL;
      int status = -1;
  
      if (!dict)
***************
*** 367,377 ****
      if (!(name = PyString_FromString("Exception")))
  	goto finally;
  
!     if (!(PyExc_Exception = PyClass_New(NULL, dict, name)))
  	goto finally;
  
      /* Now populate the dictionary with the method suite */
!     if (populate_methods(PyExc_Exception, dict, Exception_methods))
  	/* Don't need to reclaim PyExc_Exception here because that'll
  	 * happen during interpreter shutdown.
  	 */
--- 369,385 ----
      if (!(name = PyString_FromString("Exception")))
  	goto finally;
  
!     if (!(emptytuple = PyTuple_New(0)))
! 	goto finally;
!        
!     if (!(argstuple = PyTuple_Pack(3, name, emptytuple, dict)))
! 	goto finally;
!        
!     if (!(PyExc_Exception = PyType_Type.tp_new(&PyType_Type, argstuple, NULL)))
  	goto finally;
  
      /* Now populate the dictionary with the method suite */
!     if (populate_methods(PyExc_Exception, Exception_methods))
  	/* Don't need to reclaim PyExc_Exception here because that'll
  	 * happen during interpreter shutdown.
  	 */
***************
*** 383,388 ****
--- 391,398 ----
      Py_XDECREF(dict);
      Py_XDECREF(str);
      Py_XDECREF(name);
+     Py_XDECREF(emptytuple);
+     Py_XDECREF(argstuple);
      return status;
  }
  
Index: Python/pythonrun.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Python/pythonrun.c,v
retrieving revision 2.207
diff -c -r2.207 pythonrun.c
*** Python/pythonrun.c	21 Jul 2004 05:35:02 -0000	2.207
--- Python/pythonrun.c	5 Aug 2004 13:01:48 -0000
***************
*** 1001,1007 ****
  	fflush(stdout);
  	if (value == NULL || value == Py_None)
  		goto done;
! 	if (PyInstance_Check(value)) {
  		/* The error code should be in the `code' attribute. */
  		PyObject *code = PyObject_GetAttrString(value, "code");
  		if (code) {
--- 1001,1008 ----
  	fflush(stdout);
  	if (value == NULL || value == Py_None)
  		goto done;
! 	if (PyType_IsSubtype(value->ob_type, 
! 			     (PyTypeObject*)PyExc_Exception)) {
  		/* The error code should be in the `code' attribute. */
  		PyObject *code = PyObject_GetAttrString(value, "code");
  		if (code) {
***************
*** 1129,1142 ****
  		if (err) {
  			/* Don't do anything else */
  		}
! 		else if (PyClass_Check(exception)) {
! 			PyClassObject* exc = (PyClassObject*)exception;
! 			PyObject* className = exc->cl_name;
  			PyObject* moduleName =
! 			      PyDict_GetItemString(exc->cl_dict, "__module__");
  
! 			if (moduleName == NULL)
  				err = PyFile_WriteString("<unknown>", f);
  			else {
  				char* modstr = PyString_AsString(moduleName);
  				if (modstr && strcmp(modstr, "exceptions"))
--- 1130,1147 ----
  		if (err) {
  			/* Don't do anything else */
  		}
! 		else if (PyType_Check(exception)
! 			 && (((PyTypeObject*)exception)->tp_flags 
! 			     & Py_TPFLAGS_HEAPTYPE)) {
! 			PyHeapTypeObject* exc = (PyHeapTypeObject*)exception;
! 			PyObject* className = exc->name;
  			PyObject* moduleName =
! 			      PyObject_GetAttrString(exception, "__module__");
  
! 			if (moduleName == NULL) {
! 				PyErr_Clear(); /* ugh! */
  				err = PyFile_WriteString("<unknown>", f);
+ 			}
  			else {
  				char* modstr = PyString_AsString(moduleName);
  				if (modstr && strcmp(modstr, "exceptions"))
