From: <pj...@us...> - 2009-03-30 22:02:10
|
Revision: 6129 http://jython.svn.sourceforge.net/jython/?rev=6129&view=rev Author: pjenvey Date: 2009-03-30 22:02:06 +0000 (Mon, 30 Mar 2009) Log Message: ----------- only modify __module__ in classDict after it's been copied thanks Mike Bayer Modified Paths: -------------- trunk/jython/Lib/test/test_class_jy.py trunk/jython/src/org/python/core/PyType.java Modified: trunk/jython/Lib/test/test_class_jy.py =================================================================== --- trunk/jython/Lib/test/test_class_jy.py 2009-03-30 21:40:00 UTC (rev 6128) +++ trunk/jython/Lib/test/test_class_jy.py 2009-03-30 22:02:06 UTC (rev 6129) @@ -330,6 +330,11 @@ class Bar(object): self.assertEqual(__module__, module_name) + def test_dundermodule_in_class_dict_copy(self): + class_dict = {'a': 'this is a', 'b': 'this is b'} + Foo = type.__new__(type, 'Foo', (object,), class_dict) + Foo.keys = class_dict.keys + assert sorted(Foo().keys()) == sorted(['a', 'b']), sorted(Foo().keys()) class ClassMetaclassRepr(unittest.TestCase): """Verifies #1131 is fixed""" Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2009-03-30 21:40:00 UTC (rev 6128) +++ trunk/jython/src/org/python/core/PyType.java 2009-03-30 22:02:06 UTC (rev 6129) @@ -166,19 +166,6 @@ } } - if (dict.__finditem__("__module__") == null) { - PyFrame frame = Py.getFrame(); - if (frame != null) { - PyObject globals = frame.f_globals; - PyObject modname; - if ((modname = globals.__finditem__("__name__")) != null) { - dict.__setitem__("__module__", modname); - } - } - } - // XXX also __doc__ __module__ - - Class<?> proxyClass = null; if (baseClass != null || interfaces.size() != 0) { String proxyName = name; @@ -227,6 +214,19 @@ } else { dict = ((PyDictionary)dict).copy(); } + + if (dict.__finditem__("__module__") == null) { + PyFrame frame = Py.getFrame(); + if (frame != null) { + PyObject globals = frame.f_globals; + PyObject modname; + if ((modname = globals.__finditem__("__name__")) != null) { + dict.__setitem__("__module__", modname); + } + } + } + // XXX also __doc__ __module__ + newtype.dict = dict; newtype.name = name; newtype.base = best_base(bases_list); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |