Skip to content

Conversation

gvanrossum
Copy link
Member

See rominf/ordered-set-stubs#1:

class OrderedSet(MutableSet[T], Sequence[T]): ...

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.)

See rominf/ordered-set-stubs#1:
class OrderedSet(MutableSet[T], Sequence[T]): ...
works in Python 3, but not in Python 2 -- this fixes that
@JelleZijlstra
Copy link
Member

Seems fine, although this feels a bit unprincipled—how do we know this won't break some other way of subclassing the typing classes?

@gvanrossum
Copy link
Member Author

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.)

@JelleZijlstra JelleZijlstra merged commit 4dc21f0 into master Nov 14, 2018
@JelleZijlstra JelleZijlstra deleted the sized-order branch November 14, 2018 04:47
JukkaL added a commit to JukkaL/typeshed that referenced this pull request Nov 30, 2018
ilevkivskyi pushed a commit that referenced this pull request Nov 30, 2018
yedpodtrzitko pushed a commit to yedpodtrzitko/typeshed that referenced this pull request Jan 23, 2019
See rominf/ordered-set-stubs#1:
class OrderedSet(MutableSet[T], Sequence[T]): ...
works in Python 3, but not in Python 2 -- this fixes that
yedpodtrzitko pushed a commit to yedpodtrzitko/typeshed that referenced this pull request Jan 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants