Code

Opened 3 years ago

Closed 8 months ago

#15812 closed New feature (wontfix)

SortedDict.update() should accept tuples or generators

Reported by: slinkp Owned by: ryankask
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

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 slinkp 3 years ago.

Download all attachments as: .zip

Change History (13)

Changed 3 years ago by slinkp

comment:1 Changed 3 years ago by julien

  • Needs documentation set
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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 Changed 3 years ago by lrekucki

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 2 years ago by aaugustin

  • UI/UX unset

Change UI/UX from NULL to False.

comment:4 Changed 2 years ago by aaugustin

  • Easy pickings unset

Change Easy pickings from NULL to False.

comment:5 Changed 13 months ago by aaugustin

  • Component changed from Core (Other) to Utilities

comment:6 Changed 11 months ago by ryankask

  • Owner changed from nobody to ryankask
  • Status changed from new to assigned

comment:7 Changed 11 months ago by ryankask

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 11 months ago by ryankask (previous) (diff)

comment:8 Changed 11 months ago by ryankask

  • Triage Stage changed from Accepted to Ready for checkin

comment:9 Changed 11 months ago by aaugustin

  • Needs documentation unset
  • Triage Stage changed from Ready for checkin to Accepted

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

comment:10 Changed 10 months ago by ryankask

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 10 months ago by aaugustin

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

comment:12 Changed 8 months ago by timo

  • Resolution set to wontfix
  • Status changed from assigned to closed

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.