#31024: firstof template tag documentation incorrectly specifies value testing
------------------------------------------------+------------------------
Reporter: Keryn Knight | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
The documentation for `{%firstof x y z %}` says:
> Outputs the first argument variable that is not **False**. Outputs
nothing if all the passed variables are **False**.
The emphasis not mine, and indicates it's specifically testing for the
singleton False. But the example it gives as an equivalent is based on
normal [https://docs.python.org/3/library/stdtypes.html#truth-value-
testing truth value testing]:
{{{
{% if var1 %}
{{ var1 }}
{% elif var2 %}
{{ var2 }}
{% elif var3 %}
{{ var3 }}
{% endif %}
}}}
and the
[https://github.com/django/django/blob/a5855c8f0fe17b7e888bd8137874ef78012a7294/django/template/defaulttags.py#L125
code is also based on truthiness]
The documentation for how a simple `{% if ... %}` behaves meanwhile more
correctly prescribes it's function related to ''"true"'' and what that
means.
> evaluates a variable, and if that variable is “true” (i.e. exists, is
not empty, and is not a false boolean value) the contents of the block are
output
Were it actually based on **False** rather than **Falsiness**, the
following would not output ''truthy''.
{{{
>>> from django.template import Template, Context
>>> context = {'a': None,'b': False,'c': 0,'d': '','e': (),'f': [],'g':
{},'h': set(),'i': "truthy"}
>>> t = Template("{% firstof a b c d e f g h i %}")
>>> t.render(Context(context))
'truthy'
}}}
Suggestion is to clarify that it's based on truthiness/falsiness, rather
than imply it's directly based on encountering **False**.
--
Ticket URL: <https://code.djangoproject.com/ticket/31024>
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/052.f29f312ca89c6637f5000f06af3ed5d1%40djangoproject.com.