#23675: Default value for optional parameter "default" in the model field 
reference
is not specified
--------------------------------------+------------------------------------
     Reporter:  paulcdejean           |                    Owner:  nobody
         Type:  Cleanup/optimization  |                   Status:  closed
    Component:  Documentation         |                  Version:  master
     Severity:  Normal                |               Resolution:  wontfix
     Keywords:                        |             Triage Stage:  Accepted
    Has patch:  0                     |      Needs documentation:  0
  Needs tests:  0                     |  Patch needs improvement:  0
Easy pickings:  1                     |                    UI/UX:  0
--------------------------------------+------------------------------------
Changes (by aaugustin):

 * status:  new => closed
 * resolution:   => wontfix


Comment:

 I beg to differ.

 There are three strategies for defining functions with optional keyword
 arguments:

 1. `arg=None`: this works well when `None` doesn't make sense as an
 argument. The target function can assume that the argument wasn't passed
 if it's `None`.
 2. `arg=GUARD` where `GUARD` is a private singleton: this variant is
 required when the target function needs to be able to tell apart "arg set
 to `None`" and "arg not passed", which is the case here.
 3. `**kwargs`: this is an alternative to 2. The target function can check
 if `'arg' in kwargs` to check if arg was passed.

 Here, Django uses a different code path when the `default` argument is
 provided and when it isn't provided. As a consequence, Django doesn't use
 its value when it isn't provided. The argument doesn't have a default
 value; it simply isn't used at all. Implying there's a default value would
 be misleading and confuse users.

 It happens that this particular piece of code is implemented with pattern
 2 instead of 3, which makes it look like there's a default value, but that
 isn't something the users should be aware of. Worse, documenting
 `NOT_PROVIDED` would ruin pattern 2, because it only works as long as
 users don't know the guard value!

 If you aren't convinced yet, I'll simply say that this bug report is based
 upon the idea that "optional paramaters in python always have a default
 value", which is wrong. Any function that takes `**kwargs` has optional
 parameters without a default value -- see `django.shortcuts.render` for a
 good example.

--
Ticket URL: <https://code.djangoproject.com/ticket/23675#comment:2>
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 post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/069.693148a4e1c05652c03cb30670049ca9%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to