From 0b93600f48867e00f6c5a132a282939a26d34170 Mon Sep 17 00:00:00 2001 From: Michael Merickel Date: Tue, 18 Jul 2017 13:26:53 -0500 Subject: [PATCH] fix the __module__ and import path of the request after custom properties have been set previously anytime ``config.add_request_method`` was used the request would appear as ``pyramid.util.Request`` when displaying ``request.__class__``. This overwrites the ``__module__`` which fixes that issue so that it appears as ``pyramid.request.Request``. --- pyramid/tests/test_util.py | 8 ++++++++ pyramid/util.py | 3 +++ 2 files changed, 11 insertions(+) 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