From 7dddbfebaa63793c542505f73078c1545481f7c4 Mon Sep 17 00:00:00 2001 From: Anthony Baxter Date: Fri, 11 Jun 2004 15:09:41 +0000 Subject: Backport: Fix for bug #966623 - classes created with type() in an exec(, {}) don't have a __module__. Test for this case. --- Misc/NEWS | 4 ++++ Objects/typeobject.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/Misc/NEWS b/Misc/NEWS index e917e88..b01488b 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -12,6 +12,10 @@ What's New in Python 2.3.5? Core and builtins ----------------- +- Bug #966623. classes created with type() in an exec(, {}) don't + have a __module__, but code in typeobject assumed it would always + be there. + - Bug #952807: Unpickling pickled instances of subclasses of datetime.date, datetime.datetime and datetime.time could yield insane objects. Thanks to Jiwon Seo for a fix. diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 9213ff0..5898df2 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -87,6 +87,10 @@ type_module(PyTypeObject *type, void *context) if (type->tp_flags & Py_TPFLAGS_HEAPTYPE) { mod = PyDict_GetItemString(type->tp_dict, "__module__"); + if (!mod) { + PyErr_Format(PyExc_AttributeError, "__module__"); + return 0; + } Py_XINCREF(mod); return mod; } -- cgit v0.12