diff --git a/pyramid/tests/test_util.py b/pyramid/tests/test_util.py index d64f0a73f0..ab9de262e4 100644 --- a/pyramid/tests/test_util.py +++ b/pyramid/tests/test_util.py @@ -293,6 +293,14 @@ def test_reset_reify(self): foo.set_property(lambda _: 2, name='x', reify=True) self.assertEqual(1, foo.x) + def test_new_class_keeps_parent_module_name(self): + foo = self._makeOne() + self.assertEqual(foo.__module__, 'pyramid.tests.test_util') + self.assertEqual(foo.__class__.__module__, 'pyramid.tests.test_util') + foo.set_property(lambda _: 1, name='x', reify=True) + self.assertEqual(foo.__module__, 'pyramid.tests.test_util') + self.assertEqual(foo.__class__.__module__, 'pyramid.tests.test_util') + class Test_WeakOrderedSet(unittest.TestCase): def _makeOne(self): from pyramid.config import WeakOrderedSet diff --git a/pyramid/util.py b/pyramid/util.py index 2827884a34..d12cd8b8b3 100644 --- a/pyramid/util.py +++ b/pyramid/util.py @@ -97,6 +97,9 @@ def apply_properties(cls, target, properties): attrs = dict(properties) if attrs: parent = target.__class__ + # fix the module name so it appears to still be the parent + # e.g. pyramid.request instead of pyramid.util + attrs.setdefault('__module__', parent.__module__) newcls = type(parent.__name__, (parent, object), attrs) # We assign __provides__ and __implemented__ below to prevent a # memory leak that results from from the usage of this instance's