Patch supplied by Burton Radons for his own SF bug #487390: Modifying
type.__module__ behavior.

This adds the module name and a dot in front of the type name in every
type object initializer, except for built-in types (and those that
already had this).  Note that it touches lots of Mac modules -- I have
no way to test these but the changes look right.  Apologies if they're
not.  This also touches the weakref docs, which contains a sample type
object initializer.  It also touches the mmap test output, because the
mmap type's repr is included in that output.  It touches object.h to
put the correct description in a comment.
diff --git a/Modules/_curses_panel.c b/Modules/_curses_panel.c
index feecfcc..11bf5c8 100644
--- a/Modules/_curses_panel.c
+++ b/Modules/_curses_panel.c
@@ -352,7 +352,7 @@
 PyTypeObject PyCursesPanel_Type = {
     PyObject_HEAD_INIT(NULL)
     0,			/*ob_size*/
-    "curses panel",	/*tp_name*/
+    "_curses_panel.curses panel",	/*tp_name*/
     sizeof(PyCursesPanelObject),	/*tp_basicsize*/
     0,			/*tp_itemsize*/
     /* methods */
diff --git a/Modules/_cursesmodule.c b/Modules/_cursesmodule.c
index c22b500..5a7a642 100644
--- a/Modules/_cursesmodule.c
+++ b/Modules/_cursesmodule.c
@@ -1511,7 +1511,7 @@
 PyTypeObject PyCursesWindow_Type = {
 	PyObject_HEAD_INIT(NULL)
 	0,			/*ob_size*/
-	"curses window",	/*tp_name*/
+	"_curses.curses window",	/*tp_name*/
 	sizeof(PyCursesWindowObject),	/*tp_basicsize*/
 	0,			/*tp_itemsize*/
 	/* methods */
diff --git a/Modules/_sre.c b/Modules/_sre.c
index d01f087..b62b17f 100644
--- a/Modules/_sre.c
+++ b/Modules/_sre.c
@@ -2403,7 +2403,7 @@
 
 statichere PyTypeObject Pattern_Type = {
     PyObject_HEAD_INIT(NULL)
-    0, "SRE_Pattern",
+    0, "_sre.SRE_Pattern",
     sizeof(PatternObject), sizeof(SRE_CODE),
     (destructor)pattern_dealloc, /*tp_dealloc*/
     0, /*tp_print*/
@@ -2866,7 +2866,7 @@
 
 statichere PyTypeObject Match_Type = {
     PyObject_HEAD_INIT(NULL)
-    0, "SRE_Match",
+    0, "_sre.SRE_Match",
     sizeof(MatchObject), sizeof(int),
     (destructor)match_dealloc, /*tp_dealloc*/
     0, /*tp_print*/
@@ -2974,7 +2974,7 @@
 
 statichere PyTypeObject Scanner_Type = {
     PyObject_HEAD_INIT(NULL)
-    0, "SRE_Scanner",
+    0, "_sre.SRE_Scanner",
     sizeof(ScannerObject), 0,
     (destructor)scanner_dealloc, /*tp_dealloc*/
     0, /*tp_print*/
diff --git a/Modules/almodule.c b/Modules/almodule.c
index e9b2114..31af258 100644
--- a/Modules/almodule.c
+++ b/Modules/almodule.c
@@ -597,7 +597,7 @@
 static PyTypeObject Alctype = {
 	PyObject_HEAD_INIT(&PyType_Type)
 	0,				/*ob_size*/
-	"config",			/*tp_name*/
+	"al.config",			/*tp_name*/
 	sizeof(alcobject),		/*tp_basicsize*/
 	0,				/*tp_itemsize*/
 	/* methods */
@@ -1321,7 +1321,7 @@
 static PyTypeObject Alptype = {
 	PyObject_HEAD_INIT(&PyType_Type)
 	0,				/*ob_size*/
-	"port",			/*tp_name*/
+	"al.port",			/*tp_name*/
 	sizeof(alpobject),		/*tp_basicsize*/
 	0,				/*tp_itemsize*/
 	/* methods */
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index 11d0723..7c89ce0 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -1528,7 +1528,7 @@
 statichere PyTypeObject Arraytype = {
 	PyObject_HEAD_INIT(NULL)
 	0,
-	"array",
+	"array.array",
 	sizeof(arrayobject),
 	0,
 	(destructor)array_dealloc,		/* tp_dealloc */
diff --git a/Modules/bsddbmodule.c b/Modules/bsddbmodule.c
index be50208..05d2bf1 100644
--- a/Modules/bsddbmodule.c
+++ b/Modules/bsddbmodule.c
@@ -677,7 +677,7 @@
 static PyTypeObject Bsddbtype = {
 	PyObject_HEAD_INIT(NULL)
 	0,
-	"bsddb",
+	"bsddb.bsddb",
 	sizeof(bsddbobject),
 	0,
 	(destructor)bsddb_dealloc, /*tp_dealloc*/
diff --git a/Modules/cPickle.c b/Modules/cPickle.c
index 85fb7cc..425ff10 100644
--- a/Modules/cPickle.c
+++ b/Modules/cPickle.c
@@ -167,7 +167,7 @@
 }
 
 static PyTypeObject PdataType = {
-    PyObject_HEAD_INIT(NULL) 0, "Pdata", sizeof(Pdata), 0,
+    PyObject_HEAD_INIT(NULL) 0, "cPickle.Pdata", sizeof(Pdata), 0,
     (destructor)Pdata_dealloc,
     0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0L,0L,0L,0L, ""
 };
@@ -2479,7 +2479,7 @@
 static PyTypeObject Picklertype = {
     PyObject_HEAD_INIT(NULL)
     0,                            /*ob_size*/
-    "Pickler",                    /*tp_name*/
+    "cPickle.Pickler",            /*tp_name*/
     sizeof(Picklerobject),              /*tp_basicsize*/
     0,
     (destructor)Pickler_dealloc,	/* tp_dealloc */
@@ -4478,7 +4478,7 @@
 static PyTypeObject Unpicklertype = {
     PyObject_HEAD_INIT(NULL)
     0,                            /*ob_size*/
-    "Unpickler",                  /*tp_name*/
+    "cPickle.Unpickler",                  /*tp_name*/
     sizeof(Unpicklerobject),              /*tp_basicsize*/
     0,                            /*tp_itemsize*/
     /* methods */
diff --git a/Modules/cStringIO.c b/Modules/cStringIO.c
index 094804c..f85d60a 100644
--- a/Modules/cStringIO.c
+++ b/Modules/cStringIO.c
@@ -543,7 +543,7 @@
 static PyTypeObject Otype = {
   PyObject_HEAD_INIT(NULL)
   0,	       		/*ob_size*/
-  "StringO",     		/*tp_name*/
+  "cStringIO.StringO",   		/*tp_name*/
   sizeof(Oobject),       	/*tp_basicsize*/
   0,	       		/*tp_itemsize*/
   /* methods */
@@ -677,7 +677,7 @@
 static PyTypeObject Itype = {
   PyObject_HEAD_INIT(NULL)
   0,					/*ob_size*/
-  "StringI",				/*tp_name*/
+  "cStringIO.StringI",			/*tp_name*/
   sizeof(Iobject),			/*tp_basicsize*/
   0,					/*tp_itemsize*/
   /* methods */
diff --git a/Modules/cdmodule.c b/Modules/cdmodule.c
index ee58c5e..f0dd599 100644
--- a/Modules/cdmodule.c
+++ b/Modules/cdmodule.c
@@ -395,7 +395,7 @@
 PyTypeObject CdPlayertype = {
 	PyObject_HEAD_INIT(&PyType_Type)
 	0,			/*ob_size*/
-	"cdplayer",		/*tp_name*/
+	"cd.cdplayer",	/*tp_name*/
 	sizeof(cdplayerobject),	/*tp_size*/
 	0,			/*tp_itemsize*/
 	/* methods */
@@ -692,7 +692,7 @@
 PyTypeObject CdParsertype = {
 	PyObject_HEAD_INIT(&PyType_Type)
 	0,			/*ob_size*/
-	"cdparser",		/*tp_name*/
+	"cd.cdparser",		/*tp_name*/
 	sizeof(cdparserobject),	/*tp_size*/
 	0,			/*tp_itemsize*/
 	/* methods */
diff --git a/Modules/clmodule.c b/Modules/clmodule.c
index 2ff184c..13011d2 100644
--- a/Modules/clmodule.c
+++ b/Modules/clmodule.c
@@ -658,7 +658,7 @@
 static PyTypeObject Cltype = {
 	PyObject_HEAD_INIT(&PyType_Type)
 	0,			/*ob_size*/
-	"cl",			/*tp_name*/
+	"cl.cl",		/*tp_name*/
 	sizeof(clobject),	/*tp_size*/
 	0,			/*tp_itemsize*/
 	/* methods */
diff --git a/Modules/dbmmodule.c b/Modules/dbmmodule.c
index bd14df6..233487d 100644
--- a/Modules/dbmmodule.c
+++ b/Modules/dbmmodule.c
@@ -287,7 +287,7 @@
 static PyTypeObject Dbmtype = {
 	PyObject_HEAD_INIT(NULL)
 	0,
-	"dbm",
+	"dbm.dbm",
 	sizeof(dbmobject),
 	0,
 	(destructor)dbm_dealloc,  /*tp_dealloc*/
diff --git a/Modules/dlmodule.c b/Modules/dlmodule.c
index 8c77133..18b97d8 100644
--- a/Modules/dlmodule.c
+++ b/Modules/dlmodule.c
@@ -136,7 +136,7 @@
 static PyTypeObject Dltype = {
 	PyObject_HEAD_INIT(NULL)
 	0,			/*ob_size*/
-	"dl",			/*tp_name*/
+	"dl.dl",		/*tp_name*/
 	sizeof(dlobject),	/*tp_basicsize*/
 	0,			/*tp_itemsize*/
 	/* methods */
diff --git a/Modules/flmodule.c b/Modules/flmodule.c
index 25037bf..ee1f068 100644
--- a/Modules/flmodule.c
+++ b/Modules/flmodule.c
@@ -378,7 +378,7 @@
 static PyTypeObject GenericObjecttype = {
 	PyObject_HEAD_INIT(&PyType_Type)
 	0,				/*ob_size*/
-	"FORMS_object",			/*tp_name*/
+	"fl.FORMS_object",		/*tp_name*/
 	sizeof(genericobject),		/*tp_size*/
 	0,				/*tp_itemsize*/
 	/* methods */
@@ -1588,7 +1588,7 @@
 static PyTypeObject Formtype = {
 	PyObject_HEAD_INIT(&PyType_Type)
 	0,				/*ob_size*/
-	"FORMS_form",			/*tp_name*/
+	"fl.FORMS_form",		/*tp_name*/
 	sizeof(formobject),		/*tp_size*/
 	0,				/*tp_itemsize*/
 	/* methods */
diff --git a/Modules/fmmodule.c b/Modules/fmmodule.c
index 065aed6..a2eb9c6 100644
--- a/Modules/fmmodule.c
+++ b/Modules/fmmodule.c
@@ -154,7 +154,7 @@
 static PyTypeObject Fhtype = {
 	PyObject_HEAD_INIT(&PyType_Type)
 	0,				/*ob_size*/
-	"font handle",			/*tp_name*/
+	"fm.font handle",		/*tp_name*/
 	sizeof(fhobject),		/*tp_size*/
 	0,				/*tp_itemsize*/
 	/* methods */
diff --git a/Modules/gdbmmodule.c b/Modules/gdbmmodule.c
index 505ce92..72d76ea 100644
--- a/Modules/gdbmmodule.c
+++ b/Modules/gdbmmodule.c
@@ -382,7 +382,7 @@
 static PyTypeObject Dbmtype = {
     PyObject_HEAD_INIT(0)
     0,
-    "gdbm",
+    "gdbm.gdbm",
     sizeof(dbmobject),
     0,
     (destructor)dbm_dealloc,            /*tp_dealloc*/
diff --git a/Modules/linuxaudiodev.c b/Modules/linuxaudiodev.c
index e0f144b..dd462ef 100644
--- a/Modules/linuxaudiodev.c
+++ b/Modules/linuxaudiodev.c
@@ -455,7 +455,7 @@
 static PyTypeObject Ladtype = {
     PyObject_HEAD_INIT(&PyType_Type)
     0,				/*ob_size*/
-    "linux_audio_device",	/*tp_name*/
+    "linuxaudiodev.linux_audio_device", /*tp_name*/
     sizeof(lad_t),		/*tp_size*/
     0,				/*tp_itemsize*/
     /* methods */
diff --git a/Modules/md5module.c b/Modules/md5module.c
index beb743f..3ddacf5 100644
--- a/Modules/md5module.c
+++ b/Modules/md5module.c
@@ -202,7 +202,7 @@
 statichere PyTypeObject MD5type = {
 	PyObject_HEAD_INIT(NULL)
 	0,			  /*ob_size*/
-	"md5",			  /*tp_name*/
+	"md5.md5",		  /*tp_name*/
 	sizeof(md5object),	  /*tp_size*/
 	0,			  /*tp_itemsize*/
 	/* methods */
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index a4ec2d0..933e972 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -772,7 +772,7 @@
 static PyTypeObject mmap_object_type = {
 	PyObject_HEAD_INIT(0) /* patched in module init */
 	0,					/* ob_size */
-	"mmap",					/* tp_name */
+	"mmap.mmap",				/* tp_name */
 	sizeof(mmap_object),			/* tp_size */
 	0,					/* tp_itemsize */
 	/* methods */
diff --git a/Modules/mpzmodule.c b/Modules/mpzmodule.c
index bcbd238..04057f1 100644
--- a/Modules/mpzmodule.c
+++ b/Modules/mpzmodule.c
@@ -1591,7 +1591,7 @@
 static PyTypeObject MPZtype = {
 	PyObject_HEAD_INIT(NULL)
 	0,			/*ob_size*/
-	"mpz",			/*tp_name*/
+	"mpz.mpz",		/*tp_name*/
 	sizeof(mpzobject),	/*tp_size*/
 	0,			/*tp_itemsize*/
 	/* methods */
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c
index 2b6dfa5..ca0531d 100644
--- a/Modules/parsermodule.c
+++ b/Modules/parsermodule.c
@@ -174,7 +174,7 @@
 PyTypeObject PyST_Type = {
     PyObject_HEAD_INIT(NULL)
     0,
-    "st",                               /* tp_name              */
+    "parser.st",                        /* tp_name              */
     (int) sizeof(PyST_Object),          /* tp_basicsize         */
     0,                                  /* tp_itemsize          */
     (destructor)parser_free,            /* tp_dealloc           */
diff --git a/Modules/pcremodule.c b/Modules/pcremodule.c
index 7a8900d..d08d4ea 100644
--- a/Modules/pcremodule.c
+++ b/Modules/pcremodule.c
@@ -128,7 +128,7 @@
 staticforward PyTypeObject Pcre_Type = {
 	PyObject_HEAD_INIT(NULL)
 	0,			/*ob_size*/
-	"Pcre",			/*tp_name*/
+	"pcre.Pcre",		/*tp_name*/
 	sizeof(PcreObject),	/*tp_basicsize*/
 	0,			/*tp_itemsize*/
 	/* methods */
diff --git a/Modules/posixmodule.c b/Modules/posixmodule.c
index ebda8bf..08b0c46 100644
--- a/Modules/posixmodule.c
+++ b/Modules/posixmodule.c
@@ -6002,9 +6002,11 @@
 		posix_putenv_garbage = PyDict_New();
 #endif
 
+	stat_result_desc.name = MODNAME ".stat_result";
 	PyStructSequence_InitType(&StatResultType, &stat_result_desc);
 	PyDict_SetItemString(d, "stat_result", (PyObject*) &StatResultType);
 
+	statvfs_result_desc.name = MODNAME ".statvfs_result";
 	PyStructSequence_InitType(&StatVFSResultType, &statvfs_result_desc);
 	PyDict_SetItemString(d, "statvfs_result", (PyObject*) &StatResultType);
 }
diff --git a/Modules/pyexpat.c b/Modules/pyexpat.c
index 90e53b6..3ea022a 100644
--- a/Modules/pyexpat.c
+++ b/Modules/pyexpat.c
@@ -1380,7 +1380,7 @@
 static PyTypeObject Xmlparsetype = {
 	PyObject_HEAD_INIT(NULL)
 	0,				/*ob_size*/
-	"xmlparser",			/*tp_name*/
+	"pyexpat.xmlparser",		/*tp_name*/
 	sizeof(xmlparseobject) + PyGC_HEAD_SIZE,/*tp_basicsize*/
 	0,				/*tp_itemsize*/
 	/* methods */
diff --git a/Modules/regexmodule.c b/Modules/regexmodule.c
index c0e465a..c3711e6 100644
--- a/Modules/regexmodule.c
+++ b/Modules/regexmodule.c
@@ -340,7 +340,7 @@
 static PyTypeObject Regextype = {
 	PyObject_HEAD_INIT(NULL)
 	0,				     /*ob_size*/
-	"regex",			     /*tp_name*/
+	"regex.regex",			     /*tp_name*/
 	sizeof(regexobject),		     /*tp_size*/
 	0,				     /*tp_itemsize*/
 	/* methods */
diff --git a/Modules/rotormodule.c b/Modules/rotormodule.c
index cc25924..7c1131c 100644
--- a/Modules/rotormodule.c
+++ b/Modules/rotormodule.c
@@ -578,7 +578,7 @@
 statichere PyTypeObject Rotor_Type = {
 	PyObject_HEAD_INIT(NULL)
 	0,				/*ob_size*/
-	"rotor",			/*tp_name*/
+	"rotor.rotor",			/*tp_name*/
 	sizeof(Rotorobj),		/*tp_size*/
 	0,				/*tp_itemsize*/
 	/* methods */
diff --git a/Modules/selectmodule.c b/Modules/selectmodule.c
index 348987b..e5aa6eb 100644
--- a/Modules/selectmodule.c
+++ b/Modules/selectmodule.c
@@ -567,7 +567,7 @@
 	 * to be portable to Windows without using C++. */
 	PyObject_HEAD_INIT(NULL)
 	0,			/*ob_size*/
-	"poll",			/*tp_name*/
+	"select.poll",		/*tp_name*/
 	sizeof(pollObject),	/*tp_basicsize*/
 	0,			/*tp_itemsize*/
 	/* methods */
diff --git a/Modules/shamodule.c b/Modules/shamodule.c
index b3831b9..f33f907 100644
--- a/Modules/shamodule.c
+++ b/Modules/shamodule.c
@@ -467,7 +467,7 @@
 static PyTypeObject SHAtype = {
     PyObject_HEAD_INIT(NULL)
     0,			/*ob_size*/
-    "SHA",		/*tp_name*/
+    "sha.SHA",		/*tp_name*/
     sizeof(SHAobject),	/*tp_size*/
     0,			/*tp_itemsize*/
     /* methods */
diff --git a/Modules/sunaudiodev.c b/Modules/sunaudiodev.c
index e4c4c9f..e9ffd1f 100644
--- a/Modules/sunaudiodev.c
+++ b/Modules/sunaudiodev.c
@@ -434,7 +434,7 @@
 static PyTypeObject Sadtype = {
 	PyObject_HEAD_INIT(&PyType_Type)
 	0,				/*ob_size*/
-	"sun_audio_device",		/*tp_name*/
+	"sunaudiodev.sun_audio_device",	/*tp_name*/
 	sizeof(sadobject),		/*tp_size*/
 	0,				/*tp_itemsize*/
 	/* methods */
@@ -449,7 +449,7 @@
 static PyTypeObject Sadstatustype = {
 	PyObject_HEAD_INIT(&PyType_Type)
 	0,				/*ob_size*/
-	"sun_audio_device_status",	/*tp_name*/
+	"sunaudiodev.sun_audio_device_status", /*tp_name*/
 	sizeof(sadstatusobject),	/*tp_size*/
 	0,				/*tp_itemsize*/
 	/* methods */
diff --git a/Modules/svmodule.c b/Modules/svmodule.c
index ead0ca5..1e254ad 100644
--- a/Modules/svmodule.c
+++ b/Modules/svmodule.c
@@ -294,7 +294,7 @@
 PyTypeObject Capturetype = {
 	PyObject_HEAD_INIT(&PyType_Type)
 	0,				/*ob_size*/
-	"capture",			/*tp_name*/
+	"sv.capture",			/*tp_name*/
 	sizeof(captureobject),		/*tp_size*/
 	0,				/*tp_itemsize*/
 	/* methods */
@@ -898,7 +898,7 @@
 PyTypeObject Svtype = {
 	PyObject_HEAD_INIT(&PyType_Type)
 	0,			/*ob_size*/
-	"sv",			/*tp_name*/
+	"sv.sv",		/*tp_name*/
 	sizeof(svobject),	/*tp_size*/
 	0,			/*tp_itemsize*/
 	/* methods */
diff --git a/Modules/threadmodule.c b/Modules/threadmodule.c
index bdc7932..dfc5cbe 100644
--- a/Modules/threadmodule.c
+++ b/Modules/threadmodule.c
@@ -156,7 +156,7 @@
 static PyTypeObject Locktype = {
 	PyObject_HEAD_INIT(&PyType_Type)
 	0,				/*ob_size*/
-	"lock",				/*tp_name*/
+	"thread.lock",			/*tp_name*/
 	sizeof(lockobject),		/*tp_size*/
 	0,				/*tp_itemsize*/
 	/* methods */
diff --git a/Modules/timemodule.c b/Modules/timemodule.c
index a9b7a03..bcc53e0 100644
--- a/Modules/timemodule.c
+++ b/Modules/timemodule.c
@@ -223,7 +223,7 @@
 };
 
 static PyStructSequence_Desc struct_time_type_desc = {
-	"struct_time",
+	"time.struct_time",
 	NULL,
 	struct_time_type_fields,
 	9,
diff --git a/Modules/xreadlinesmodule.c b/Modules/xreadlinesmodule.c
index efc3de5..4511f17 100644
--- a/Modules/xreadlinesmodule.c
+++ b/Modules/xreadlinesmodule.c
@@ -135,7 +135,7 @@
 static PyTypeObject XReadlinesObject_Type = {
 	PyObject_HEAD_INIT(NULL)
 	0,
-	"xreadlines",
+	"xreadlines.xreadlines",
 	sizeof(PyXReadlinesObject),
 	0,
 	(destructor)xreadlines_dealloc,		/* tp_dealloc */
diff --git a/Modules/xxmodule.c b/Modules/xxmodule.c
index 29b874b..0ee9f7a 100644
--- a/Modules/xxmodule.c
+++ b/Modules/xxmodule.c
@@ -98,7 +98,7 @@
 	 * to be portable to Windows without using C++. */
 	PyObject_HEAD_INIT(NULL)
 	0,			/*ob_size*/
-	"Xxo",			/*tp_name*/
+	"xxmodule.Xxo",		/*tp_name*/
 	sizeof(XxoObject),	/*tp_basicsize*/
 	0,			/*tp_itemsize*/
 	/* methods */
diff --git a/Modules/zlibmodule.c b/Modules/zlibmodule.c
index 2df7f6f..3f2fd80 100644
--- a/Modules/zlibmodule.c
+++ b/Modules/zlibmodule.c
@@ -798,7 +798,7 @@
 statichere PyTypeObject Comptype = {
     PyObject_HEAD_INIT(0)
     0,
-    "Compress",
+    "zlib.Compress",
     sizeof(compobject),
     0,
     (destructor)Comp_dealloc,       /*tp_dealloc*/
@@ -815,7 +815,7 @@
 statichere PyTypeObject Decomptype = {
     PyObject_HEAD_INIT(0)
     0,
-    "Decompress",
+    "zlib.Decompress",
     sizeof(compobject),
     0,
     (destructor)Decomp_dealloc,     /*tp_dealloc*/