[Python-ideas] issubclass(collections.OrderedDict, collections.Sequence)

Nick Coghlan ncoghlan at gmail.com
Wed Oct 8 07:29:30 CEST 2014


On 8 Oct 2014 14:09, "Guido van Rossum" <guido at python.org> wrote:
>
> On Tue, Oct 7, 2014 at 8:54 PM, <random832 at fastmail.us> wrote:
>>
>> On Tue, Oct 7, 2014, at 21:09, Stephen J. Turnbull wrote:
>> > But this requires a comparison of the two orders, and "ordering
>> > relation" is not a type available in the stdlib.
>>
>> This has nothing to do with comparable types - the only comparison being
>> done on the members themselves is equality.
>>
>> i.e. if the main sequence is [5, 1, 3, 2, 4], it's true for [5, 2, 4]
>> but not [5, 4, 1].
>>
>> Think of it as being the question of whether "51234" matches "5.*2.*4"
>> (it does) or "5.*4.*1" (it does not). But if the argument is a set
>> instead he wants it to be whether it's a subset rather than a
>> subsequence.
>
>
> This is the first understandable description of Ram's use case that I
have seen. Thank you!

And now that I also understand it, I can note that this kind of thing
*does* occasionally come up in testing polymorphic filtering operations. If
the original container has a non-arbitrary ordering, the filtering
operation should preserve it. If the container ordering is arbitrary (e.g.
set, dict) then filtering may also change the relative ordering of the
retained elements.

That observation also gives a possible concrete semantic definition as to
what "Ordered" might mean: adding or removing a new element never changes
the relative ordering of the other elements in the container.

Under that definition, set and dict aren't ordered, since the order of
iteration can be affected by the current number of items in the container.

As an example of the difference mattering in practice, "assertSameElements"
is specifically designed to help deal with cases where you're comparing an
unordered result to ordered reference data.

Cheers,
Nick.

>
> --
> --Guido van Rossum (python.org/~guido)
>
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20141008/2923a6f0/attachment.html>


More information about the Python-ideas mailing list