Opened 14 years ago

Closed 11 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: 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

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 14 years ago.

Download all attachments as: .zip

Change History (13)

by Paul Winkler, 14 years ago

Attachment: sorteddict.patch added

comment:1 by Julien Phalip, 14 years ago

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: http://docs.djangoproject.com/en/dev/ref/utils/#django.utils.datastructures.SortedDict

comment:2 by Łukasz Rekucki, 14 years ago

Sorry for the noise, but:

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

strikes me as far less readable then:

hasattr(dict_, 'iteritems')

comment:3 by Aymeric Augustin, 13 years ago

UI/UX: unset

Change UI/UX from NULL to False.

comment:4 by Aymeric Augustin, 13 years ago

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:5 by Aymeric Augustin, 12 years ago

Component: Core (Other)Utilities

comment:6 by Ryan Kaskel, 12 years ago

Owner: changed from nobody to Ryan Kaskel
Status: newassigned

comment:7 by Ryan Kaskel, 12 years ago

I've taken a slightly different approach here and have followed Python's OrderedDict by using MutableMapping.update (http://hg.python.org/releasing/2.7.3/file/7bb96963d067/Lib/_abcoll.py#l483).

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: https://github.com/django/django/pull/1158

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

comment:8 by Ryan Kaskel, 12 years ago

Triage Stage: AcceptedReady for checkin

comment:9 by Aymeric Augustin, 12 years ago

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 by Ryan Kaskel, 11 years ago

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 by Aymeric Augustin, 11 years ago

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

comment:12 by Tim Graham, 11 years ago

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