Opened 8 years ago

Closed 8 years ago

#28037 closed Bug (fixed)

Incorrect return type in QueryDict.items()/values() docs examples

Reported by: Daniel F Moisset Owned by: nobody
Component: Documentation Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description (last modified by Tim Graham)

There is an inconsistency about the defined behaviour of QueryDict.items() (a similar thing happens for QueryDict.values():

  • The current implementation actually returns a generator object (supporting iteration only)
  • The documentation says that it is "just like the standard dictionary items() method", which in Python3 returns a dict_items object (a view object, supporting set-like operations)
  • But the example in the documentation 2 lines below that show a standard python list (supporting indexing)

I see 2 different was to fix this:

  1. Update the documentation and make explicit that a generator is returned and that Querydict is a bit different than python dicts
  2. Make QueryDict behave more like python by returning a set(). This should not break backwards compatibility (a set is more general than a generator), but use more memory (because the set must be fully built instead of generated lazily)

I can provide patches for any of these options, but some core devs recommended me getting an opinion of which is the right solution before moving forward.

Change History (3)

comment:1 by Tim Graham, 8 years ago

Component: HTTP handlingDocumentation
Description: modified (diff)
Summary: Inconsistency on QueryDict.items and documentationIncorrect return type in QueryDict.items()/values() docs examples
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

Fixing the documentation looks like the correct way to proceed. The current example shows the behavior on Python 2 was was to return a list.

comment:2 by Daniel F Moisset, 8 years ago

Has patch: set

comment:3 by Tim Graham <timograham@…>, 8 years ago

Resolution: fixed
Status: newclosed

In 8ab7ce85:

Fixed #28037 -- Clarified that QueryDict.items()/values() are generators.

Note: See TracTickets for help on using tickets.
Back to Top