Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit c055bce

Browse filesBrowse files
authored
Revert "Make api_view respect standard wrapper assignments (#8291)"
This reverts commit 9c97946.
1 parent 2d52c9e commit c055bce
Copy full SHA for c055bce

File tree

Expand file treeCollapse file tree

2 files changed

+16
-14
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+16
-14
lines changed

‎rest_framework/decorators.py

Copy file name to clipboardExpand all lines: rest_framework/decorators.py
+16-4Lines changed: 16 additions & 4 deletions
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

‎tests/test_decorators.py

Copy file name to clipboardExpand all lines: tests/test_decorators.py
-10Lines changed: 0 additions & 10 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.