Move Sized earlier in the bases of Sequence#2602
Conversation
See rominf/ordered-set-stubs#1: class OrderedSet(MutableSet[T], Sequence[T]): ... works in Python 3, but not in Python 2 -- this fixes that
|
Seems fine, although this feels a bit unprincipled—how do we know this won't break some other way of subclassing the typing classes? |
|
Indeed, we don't know. Though then that other way would break with Python 3. FWIW I looked at the source of typing.py, and there it's different again: The Python 2 source derives Sequence from either (Sized, Reversible, Container), or (Sized, Iterable, Container), while the Python 3 source allows those two or (Reversible, Collection), where Collection derives from (Sized, Iterable, Container). So the relative order of Sized and Reversible is not fixed, but I didn't change that in this PR -- I'm only making Sized come before Iterable consistently, which matches that. (Also note that calculating the MRO is not black magic -- it finds a unique solution that preserves the relative order of base classes and satisfies some other constraint that makes it unique.) |
This reverts commit 4dc21f0. Fixes python#2655.
See rominf/ordered-set-stubs#1: class OrderedSet(MutableSet[T], Sequence[T]): ... works in Python 3, but not in Python 2 -- this fixes that
…ython#2657) This reverts commit 4dc21f0. Fixes python#2655.
See rominf/ordered-set-stubs#1:
works in Python 3, but not in Python 2 -- this fixes that.
(I haven't run the tests yet -- if they show problems with this I may just withdraw this.)