summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Merickel <michael@merickel.org>2021-02-20 14:43:40 -0600
committerGitHub <noreply@github.com>2021-02-20 14:43:40 -0600
commitea3050858e4542fc12a3208d9a142eec8b0706cf (patch)
treee31a5d7fa12f509cef5ecb6feee94cf3d29cc4c2
parent5b63fb8ecff82d448970b7e2d7b9dd078d4ed438 (diff)
parent24ea7860842f0d5ac366732f5921dde1e285cdf7 (diff)
downloadpyramid-ea3050858e4542fc12a3208d9a142eec8b0706cf.tar.gz
pyramid-ea3050858e4542fc12a3208d9a142eec8b0706cf.tar.bz2
pyramid-ea3050858e4542fc12a3208d9a142eec8b0706cf.zip
Merge pull request #3657 from luhn/reify-sphinx
Remove update_wrapper from reify
-rw-r--r--CHANGES.rst3
-rw-r--r--src/pyramid/decorator.py5
-rw-r--r--tests/test_config/test_views.py15
-rw-r--r--tests/test_decorator.py23
4 files changed, 27 insertions, 19 deletions
diff --git a/CHANGES.rst b/CHANGES.rst
index e9b222993..887c8ce95 100644
--- a/CHANGES.rst
+++ b/CHANGES.rst
@@ -4,6 +4,9 @@
- Break potential reference cycle between ``request`` and ``context``.
See https://github.com/Pylons/pyramid/pull/3649
+- Remove ``update_wrapper`` from ``pyramid.decorator.reify``.
+ See https://github.com/Pylons/pyramid/pull/3657
+
2.0b0 (2020-12-15)
==================
diff --git a/src/pyramid/decorator.py b/src/pyramid/decorator.py
index 56c74c5b6..3215b1b38 100644
--- a/src/pyramid/decorator.py
+++ b/src/pyramid/decorator.py
@@ -1,6 +1,3 @@
-from functools import update_wrapper
-
-
class reify:
"""Use as a class method decorator. It operates almost exactly like the
Python ``@property`` decorator, but it puts the result of the method it
@@ -35,7 +32,7 @@ class reify:
def __init__(self, wrapped):
self.wrapped = wrapped
- update_wrapper(self, wrapped)
+ self.__doc__ = wrapped.__doc__
def __get__(self, inst, objtype=None):
if inst is None:
diff --git a/tests/test_config/test_views.py b/tests/test_config/test_views.py
index 65271f0d6..fcccbfba3 100644
--- a/tests/test_config/test_views.py
+++ b/tests/test_config/test_views.py
@@ -4289,21 +4289,6 @@ class Test_view_description(unittest.TestCase):
self.assertEqual(result, 'function tests.test_config.test_views.view')
-class Test_viewdefaults(unittest.TestCase):
- def _makeOne(self, wrapped):
- from pyramid.decorator import reify
-
- return reify(wrapped)
-
- def test_dunder_attrs_copied(self):
- from pyramid.config.views import viewdefaults
-
- decorator = self._makeOne(viewdefaults)
- self.assertEqual(decorator.__doc__, viewdefaults.__doc__)
- self.assertEqual(decorator.__name__, viewdefaults.__name__)
- self.assertEqual(decorator.__module__, viewdefaults.__module__)
-
-
class DummyRegistry:
utility = None
diff --git a/tests/test_decorator.py b/tests/test_decorator.py
index b9a1f1e9d..0da8380f8 100644
--- a/tests/test_decorator.py
+++ b/tests/test_decorator.py
@@ -1,3 +1,4 @@
+import inspect
import unittest
@@ -25,6 +26,28 @@ class TestReify(unittest.TestCase):
result = decorator.__get__(None)
self.assertEqual(result, decorator)
+ def test_copy_docstring(self):
+ def wrapped(inst):
+ """Test doc"""
+ return 'a' # pragma: no cover
+
+ decorator = self._makeOne(wrapped)
+ assert decorator.__doc__ == 'Test doc'
+
+ def test_not_function(self):
+ """
+ Because reify'd methods act as attributes, it's important that they
+ aren't recognized as a function. Otherwise tools like Sphinx may
+ misbehave, like in https://github.com/Pylons/pyramid/issues/3655
+
+ """
+
+ def wrapped(inst):
+ return 'a' # pragma: no cover
+
+ decorator = self._makeOne(wrapped)
+ assert not inspect.isfunction(decorator)
+
class Dummy:
pass