Skip to content

Commit a780e80

Browse files
authored
Revert "Make api_view respect standard wrapper assignments (#8291)" (#8297)
This reverts commit 9c97946.
1 parent 2d52c9e commit a780e80

File tree

2 files changed

+16
-14
lines changed

2 files changed

+16
-14
lines changed

Diff for: rest_framework/decorators.py

+16-4
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
methods on viewsets that should be included by routers.
88
"""
99
import types
10-
from functools import update_wrapper
1110

1211
from django.forms.utils import pretty_name
1312

@@ -23,8 +22,18 @@ def api_view(http_method_names=None):
2322

2423
def decorator(func):
2524

26-
class WrappedAPIView(APIView):
27-
pass
25+
WrappedAPIView = type(
26+
'WrappedAPIView',
27+
(APIView,),
28+
{'__doc__': func.__doc__}
29+
)
30+
31+
# Note, the above allows us to set the docstring.
32+
# It is the equivalent of:
33+
#
34+
# class WrappedAPIView(APIView):
35+
# pass
36+
# WrappedAPIView.__doc__ = func.doc <--- Not possible to do this
2837

2938
# api_view applied without (method_names)
3039
assert not(isinstance(http_method_names, types.FunctionType)), \
@@ -43,6 +52,9 @@ def handler(self, *args, **kwargs):
4352
for method in http_method_names:
4453
setattr(WrappedAPIView, method.lower(), handler)
4554

55+
WrappedAPIView.__name__ = func.__name__
56+
WrappedAPIView.__module__ = func.__module__
57+
4658
WrappedAPIView.renderer_classes = getattr(func, 'renderer_classes',
4759
APIView.renderer_classes)
4860

@@ -61,7 +73,7 @@ def handler(self, *args, **kwargs):
6173
WrappedAPIView.schema = getattr(func, 'schema',
6274
APIView.schema)
6375

64-
return update_wrapper(WrappedAPIView.as_view(), func)
76+
return WrappedAPIView.as_view()
6577

6678
return decorator
6779

Diff for: tests/test_decorators.py

-10
Original file line numberDiff line numberDiff line change
@@ -162,16 +162,6 @@ def view(request):
162162

163163
assert isinstance(view.cls.schema, CustomSchema)
164164

165-
def test_wrapper_assignments(self):
166-
@api_view(["GET"])
167-
def test_view(request):
168-
"""example docstring"""
169-
pass
170-
171-
assert test_view.__name__ == "test_view"
172-
assert test_view.__doc__ == "example docstring"
173-
assert test_view.__qualname__ == "DecoratorTestCase.test_wrapper_assignments.<locals>.test_view"
174-
175165

176166
class ActionDecoratorTestCase(TestCase):
177167

0 commit comments

Comments
 (0)