Validity of `collections.deque` as `typing.Sequence`
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 5.1k
- Forks
- 2.1k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 82
Description
Hi
Based on this discussion on pyright: https://github.com/microsoft/pyright/discussions/7989#discussioncomment-9548709
A collections.deque is a valid typing.Sequence. However, typing.Sequence allows being sliceable, while a collections.deque does not support slicing. This makes room to make errors that is not caught by static type checkers like pyright and mypy.
It seems like this normally would be reported, but the errors are suppressed by type-ignore comments found here.
Is there any other way of handling this so that trying to slice a deque would result in a type-error?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with stdlib/collections/init.pyi around line 258 and read the linked Pyright discussion. Compare how pyright and mypy handle the current type-ignore comments and deque's Sequence relationship. Done means identifying and agreeing on a typeshed-compatible way to represent the slicing limitation, with the relevant checker behavior accounted for.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100