Skip to content

Validity of collections.deque as collections.abc.Sequence #7989

Answered by erictraut
einarwar asked this question in Q&A
Discussion options

You must be logged in to vote

This isn't a bug in pyright, which is working correctly given the type information provided to it.

This is arguably a bug in the implementation of deque which doesn't honor the Liskov Substitution Principle. The LSP is a fundamental rule in object-oriented programming, and deque is violating it. The deque class inherits from MutableSequence, but it doesn't implement all of the functionality of MutableSequence.

Type checkers like pyright and mypy will detect and report LSP violations like this, but in this case the maintainers of typeshed have suppressed the error with a # type: ignore comment. See here.

You could ask the typeshed maintainers if they can think of a better way to handle thi…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@AlexWaygood
Comment options

Answer selected by einarwar
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants