Skip to content

Commit

Permalink
Merge pull request #3129 from mmerickel/fix-request-module-name
Browse files Browse the repository at this point in the history
fix the __module__ and import path of the request after custom proper…
  • Loading branch information
mmerickel committed Jul 19, 2017
2 parents 8763d3e + 0b93600 commit 90f64a1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pyramid/tests/test_util.py
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions pyramid/util.py
Expand Up @@ -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
Expand Down

0 comments on commit 90f64a1

Please sign in to comment.