#35915: QueryDict __getitem__ returns an empty list when the value is an empty list
--------------------------------------+------------------------------------
Reporter: Nguyễn Hồng Quân | Owner: (none)
Type: Cleanup/optimization | Status: new
Component: HTTP handling | Version: 5.1
Severity: Normal | Resolution:
Keywords: querydict | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Sarah Boyce):
* stage: Unreviewed => Accepted
* summary: QueryDict __getitem__ returns list which is surpising =>
QueryDict __getitem__ returns an empty list when the value is an empty
list
Comment:
> Could we change this behavior? I know that we don't have a perfect
solution, but returning None in this case is less bad than empty list [],
because it is easier to annotate type.
It's been this way a very long time, I'm not sure what the implications of
changing it would be (in terms of compatibility). I also think changing it
for easier type annotations is not a strong argument here. You could raise
this topic on the [
https://forum.djangoproject.com/ Django forum] and get
others opinions if you wish to change it.
That being said, I think a docs adjustment is required (note that the
docstring states `Return the last data value for this key, or [] if it's
an empty list; raise KeyError if not found.`).
Accepting on that basis.
--
Ticket URL: <
https://code.djangoproject.com/ticket/35915#comment:1>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.