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 johnthagen, 4 years ago

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.

comment:2 by johnthagen, 4 years ago

Summary: Incorrect exception raising syntax in documentationInconsistent exception raising syntax in documentation

comment:3 by Tim Graham, 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 Mariusz Felisiak, 4 years ago

Resolution: invalid
Status: newclosed
Type: UncategorizedCleanup/optimization

Both versions work fine. I agree with Tim, it's not worth changing.

Note: See TracTickets for help on using tickets.
Back to Top