Reimplement request attribute access w/ __getattr__#5617
Merged
carltongibson merged 3 commits intoencode:masterfrom Nov 22, 2017
Merged
Reimplement request attribute access w/ __getattr__#5617carltongibson merged 3 commits intoencode:masterfrom
carltongibson merged 3 commits intoencode:masterfrom
Conversation
Collaborator
|
@rpkilby OK, too early... Tests pass but if |
Contributor
Author
|
I might have this completely wrong, as I don't know much about the cpython internals, but... my understanding is that the underlying c code calls In essence:
|
Contributor
Author
|
I just did a simple timeit test, and the PR does seem to be faster (which makes sense, since there are less caught exceptions. I used the following test: class Perf(TestCase):
def test_perf(self):
from timeit import repeat
wsgi_request = factory.get('/')
request = Request(wsgi_request)
# non-existent attribute
def foo():
try:
request.foo
except AttributeError:
pass
# attribute exists on WSGIRequest
def body():
request.body
# attribute exists on DRF Request
def _request():
request._request
print(min(repeat(foo, number=100000)))
print(min(repeat(body, number=100000)))
print(min(repeat(_request, number=100000)))
raise Exception('done')
|
Collaborator
|
OK. It does read that way. Good linking skills. |
carltongibson
approved these changes
Nov 22, 2017
pchiquet
pushed a commit
to pchiquet/django-rest-framework
that referenced
this pull request
Nov 17, 2020
* Add tests for proxying WSGIRequest attributes in Request. * Add request attribute exception test * Reimplement request attribute access
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Supersedes #5576. Many thanks to @yotamofek for the original PR.