{{{
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?
--
Ticket URL: <https://code.djangoproject.com/ticket/32378>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
Comment (by johnthagen):
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/32378#comment:1>
--
Ticket URL: <https://code.djangoproject.com/ticket/32378#comment:2>
Comment (by Tim Graham):
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()`).
--
Ticket URL: <https://code.djangoproject.com/ticket/32378#comment:3>
* status: new => closed
* type: Uncategorized => Cleanup/optimization
* resolution: => invalid
Comment:
Both versions work fine. I agree with Tim, it's not worth changing.
--
Ticket URL: <https://code.djangoproject.com/ticket/32378#comment:4>