Opened 4 years ago
Closed 4 years ago
#32378 closed Cleanup/optimization (invalid)
Inconsistent exception raising syntax in documentation
Reported by: | johnthagen | Owned by: | nobody |
---|---|---|---|
Component: | Documentation | Version: | dev |
Severity: | Normal | Keywords: | |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
https://docs.djangoproject.com/en/dev/ref/views/#the-403-http-forbidden-view
from django.core.exceptions import PermissionDenied def edit(request, pk): if not request.user.is_staff: raise PermissionDenied # ...
Should that be raise PermissionDenied()
to raise an instance?
Change History (4)
comment:1 by , 4 years ago
comment:2 by , 4 years ago
Summary: | Incorrect exception raising syntax in documentation → Inconsistent exception raising syntax in documentation |
---|
comment:3 by , 4 years ago
If I had to choose a style, I wouldn't include unnecessary parentheses but I'm not sure it's even worth creating the noise in commit history as I don't think it's bothering anyone. I feel like this came up before but it may not have since there are some instances of unnecessary prantheses in Django's code itself - I only found one example in the docs: topics/db/transactions.txt: raise SomeError()
).
comment:4 by , 4 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
Type: | Uncategorized → Cleanup/optimization |
Both versions work fine. I agree with Tim, it's not worth changing.
Looking into this closer, it looks like this is actually valid Python: https://docs.python.org/3/reference/simple_stmts.html#the-raise-statement
"If it is a class, the exception instance will be obtained when needed by instantiating the class with no arguments."
I'll leave the ticket open to see if the Django team wants to still fix this for style consistency purposes.