#31070: Add a check for URLconfs that mix named and unnamed capture groups
-------------------------------------+-------------------------------------
     Reporter:  Baptiste Mispelon    |                    Owner:  Baptiste
                                     |  Mispelon
         Type:  New feature          |                   Status:  assigned
    Component:  Core (System         |                  Version:  master
  checks)                            |
     Severity:  Normal               |               Resolution:
     Keywords:                       |             Triage Stage:  Accepted
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  1
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Baptiste Mispelon):

 Replying to [comment:3 Carlton Gibson]:

 Hi Carlton,

 My reasoning for suggesting a non-capturing group was to assume that the
 current pattern was working correctly as-is.
 In the case of a mixed pattern (mixing named and unnamed capture groups)
 it means that all the unnamed groups can be rewritten as non-capturing
 ones and the pattern should keep working exactly the same (because of
 Django's documented behavior of dropping unnamed groups when a mixed
 pattern is used).
 So the warning would encourage users to be more explicit about what
 they're capturing or not.


 As for the second issue (checking view signatures), I hadn't thought about
 the case of CBVs.
 I just checked and CBVs actually inherit the signature of their
 `dispatch()` method (because of the calls to `update_wrapper` which sets
 the `__wrapped__` attribute used by `inspect.signature(...)` [1]).
 Still, I'm not sure if a lot of people actually bother refining the
 signatures of their `dispatch()` methods to match their use-case.

 I also assume that the majority of signature-mismatch errors will be
 caught directly when trying to use the view. I guess the only edge-case
 that my proposal would catch would be an optional capture group that
 doesn't match the view's signature. That doesn't seem like a huge win, I
 agree.


 [1]
 
https://github.com/django/django/blob/d8e233352877c37c469687287e7761e05bdae94e/django/views/generic/base.py#L78

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31070#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.6eab4e6091bf665fa05bd29b187d7c0c%40djangoproject.com.

Reply via email to