Opened 6 years ago

Closed 3 years ago

#15812 closed New feature (wontfix)

SortedDict.update() should accept tuples or generators

Reported by: Paul Winkler Owned by: Ryan Kaskel
Component: Utilities Version: master
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


dict.update() accepts dictionaries, tuples of pairs, lists of pairs, or any generator of pairs.
But SortedDict.update() only accepts dicts.

This patch fixes that. With test.

Attachments (1)

sorteddict.patch (1.5 KB) - added by Paul Winkler 6 years ago.

Download all attachments as: .zip

Change History (13)

Changed 6 years ago by Paul Winkler

Attachment: sorteddict.patch added

comment:1 Changed 6 years ago by Julien Phalip

Needs documentation: set
Triage Stage: UnreviewedAccepted

I think that makes sense. Perhaps the docs could be improved too, giving more examples about the various possibilities:

comment:2 Changed 6 years ago by Łukasz Rekucki

Sorry for the noise, but:

getattr(dict_, 'iteritems', None) is not None

strikes me as far less readable then:

hasattr(dict_, 'iteritems')

comment:3 Changed 5 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:4 Changed 5 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:5 Changed 4 years ago by Aymeric Augustin

Component: Core (Other)Utilities

comment:6 Changed 4 years ago by Ryan Kaskel

Owner: changed from nobody to Ryan Kaskel
Status: newassigned

comment:7 Changed 4 years ago by Ryan Kaskel

I've taken a slightly different approach here and have followed Python's OrderedDict by using MutableMapping.update (

While Python's dict does indeed take any iterable of 2-item pairs, it also takes extra keyword arguments.

I didn't document those here since it doesn't preserve ordering but I did link to Python's dict.update documentation.

SortedDict.update now behaves just like dict.update and OrderedDict.update.

Pull request here:

Last edited 4 years ago by Ryan Kaskel (previous) (diff)

comment:8 Changed 4 years ago by Ryan Kaskel

Triage Stage: AcceptedReady for checkin

comment:9 Changed 4 years ago by Aymeric Augustin

Needs documentation: unset
Triage Stage: Ready for checkinAccepted

Please do not mark your own patches as RFC; have them reviewed by another contributor. Thank you!

comment:10 Changed 4 years ago by Ryan Kaskel

This may become irrelevant if Django 1.7 switches to OrderedDict.

Is there a ticket tracking the update of that data structure or the removal of Py2.6 related code in general?

comment:11 Changed 4 years ago by Aymeric Augustin

No, there isn't, we're doing it piecemeal.

comment:12 Changed 3 years ago by Tim Graham

Resolution: wontfix
Status: assignedclosed
Note: See TracTickets for help on using tickets.
Back to Top