Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove update_wrapper from reify #3657

Merged
merged 4 commits into from
Feb 20, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ Unreleased
- 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)
==================

Expand Down
5 changes: 1 addition & 4 deletions src/pyramid/decorator.py
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -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:
Expand Down
15 changes: 0 additions & 15 deletions tests/test_config/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -4289,21 +4289,6 @@ def view(): # pragma: no cover
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

Expand Down
23 changes: 23 additions & 0 deletions tests/test_decorator.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import inspect
import unittest


Expand Down Expand Up @@ -25,6 +26,28 @@ def wrapped(inst):
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