-
-
Notifications
You must be signed in to change notification settings - Fork 6.9k
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
Reimplement request attribute access w/ __getattr__ #5617
Reimplement request attribute access w/ __getattr__ #5617
Conversation
@rpkilby OK, too early... Tests pass but if |
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:
|
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')
|
OK. It does read that way. Good linking skills. |
* Add tests for proxying WSGIRequest attributes in Request. * Add request attribute exception test * Reimplement request attribute access
Supersedes #5576. Many thanks to @yotamofek for the original PR.