[Python-Dev] PEP 431 Updates
Steven D'Aprano
steve at pearwood.info
Mon Jan 28 23:17:46 CET 2013
On 28/01/13 23:52, Antoine Pitrou wrote:
> Le Mon, 28 Jan 2013 22:31:29 +1000,
> Nick Coghlan<ncoghlan at gmail.com> a écrit :
>>
>>>> 6. Under "New collections"
>>>>
>>>> Why both lists and sets?
>>>
>>> Because pytz did it. But yes, you are right, an ordered set is a
>>> better solution. Baseing it on OrderedDict seems like a hack,
>>> though. I could implement a custom orderedset, of course.
>>
>> Sets themselves have an honourable history of just being a thin
>> wrapper around dictionaries with all the values set to None (although
>> they're not implemented that way any more). Whether you create an
>> actual OrderedSet class, or just expose the result of calling keys()
>> on an OrderedDict instance is just an implementation detail, though.
>
> Why the complication? Just expose a regular set and let users call
> sorted() if that's what they want.
An OrderedSet is not a sorted set.
An OrderedSet, like an OrderedDict, remembers *insertion order*, it does
not automatically sort the keys. So if datetime needs an ordered set, and
I have no opinion on whether or not it really does, calling sorted() on a
regular set is not the solution.
--
Steven
More information about the Python-Dev
mailing list