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)
Change History (13)
by , 14 years ago
Attachment: | sorteddict.patch added |
---|
comment:1 by , 14 years ago
Needs documentation: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 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:5 by , 12 years ago
Component: | Core (Other) → Utilities |
---|
comment:6 by , 12 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:7 by , 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
comment:8 by , 12 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
comment:9 by , 12 years ago
Needs documentation: | unset |
---|---|
Triage Stage: | Ready for checkin → Accepted |
Please do not mark your own patches as RFC; have them reviewed by another contributor. Thank you!
comment:10 by , 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:12 by , 11 years ago
Resolution: | → wontfix |
---|---|
Status: | assigned → closed |
SortedDict has been deprecated in 07876cf02b6db453ca0397c29c225668872fa96d
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