#26472: Allow finer granularity in the ability to silence checks
--------------------------------------+------------------------------------
     Reporter:  Peter Zsoldos         |                    Owner:  nobody
         Type:  New feature           |                   Status:  new
    Component:  Core (System checks)  |                  Version:  dev
     Severity:  Normal                |               Resolution:
     Keywords:                        |             Triage Stage:  Accepted
    Has patch:  0                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  0                     |                    UI/UX:  0
--------------------------------------+------------------------------------

Comment (by Adam Johnson):

 > would a dictionary based setting make sense?

 I'm not hot on the idea of this settings approach:

 1. It centralizes check silencing unnecessarily. It makes more sense to
 silence a check next to the relevant defintion, where one could write a
 comment about *why*.
 2.  Not every object has a dotted path. For example if something is
 defined inside a functino closure it will have `<locals>` inside its
 `__qualname__`, so one couldn't refer to it with a setting. This can come
 up pretty easily, such as model classes extended by class decorators.

 > I had an idea to use a similar syntax as flake8 which uses `# NOQA` to
 ignore warnings on a particular line.

 I'm also not in favour of a comment-based approach. It's a nice idea, but
 it would require Django to re-parse and tokenize the code to find the
 comments, which would significantly increase runtime cost. IMO this kind
 of operation is best reserved for linters.

 ----

 I propose adding a function to silence checks:

 {{{
 def silence_check(id_, obj=None):
 }}}

 This should be general enough since `CheckMessage.id` can be *any* object.

 For objects like fields, one could call it after the definition:

 {{{
 class Book(models.Model):
     title = ...
     silence_check("models.E999", title)
 }}}

 It could also support decorator syntax:

 {{{
 @silence_check("models.E999")
 class Book(models.Model):
     ...
 }}}

 ...which would also allow calls like this:

 {{{
 class Book(models.Model):
     title = silence_check(
         "models.E999",
         models.CharField(...),
     )
 }}}

 The implementation can use a weak dict of objects to the set of silenced
 check ID's. Using a weak dict will allow silencing to be applied to
 temporary objects without causing permanent references to be held by the
 checks framework.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/26472#comment:5>
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/066.f7d7b2a46702560ac286ac291e73cfaa%40djangoproject.com.

Reply via email to