diff options
| author | Michael Merickel <michael@merickel.org> | 2017-07-18 13:26:53 -0500 |
|---|---|---|
| committer | Michael Merickel <michael@merickel.org> | 2017-07-18 13:28:22 -0500 |
| commit | 0b93600f48867e00f6c5a132a282939a26d34170 (patch) | |
| tree | f4da4c5ec3976a106dfd02a2fe3cd4b26cf0ac49 | |
| parent | 8763d3e46468f89747e1fd6e147468852301a9a0 (diff) | |
| download | pyramid-0b93600f48867e00f6c5a132a282939a26d34170.tar.gz pyramid-0b93600f48867e00f6c5a132a282939a26d34170.tar.bz2 pyramid-0b93600f48867e00f6c5a132a282939a26d34170.zip | |
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``.
| -rw-r--r-- | pyramid/tests/test_util.py | 8 | ||||
| -rw-r--r-- | pyramid/util.py | 3 |
2 files changed, 11 insertions, 0 deletions
diff --git a/pyramid/tests/test_util.py b/pyramid/tests/test_util.py index d64f0a73f..ab9de262e 100644 --- a/pyramid/tests/test_util.py +++ b/pyramid/tests/test_util.py @@ -293,6 +293,14 @@ class Test_InstancePropertyMixin(unittest.TestCase): 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 2827884a3..d12cd8b8b 100644 --- a/pyramid/util.py +++ b/pyramid/util.py @@ -97,6 +97,9 @@ class InstancePropertyHelper(object): 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 |
