Possibility to type `tuple.__hash__` to only accept hashable items
Nobody has claimed this yet.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 35/100
- Issue type
- Feature
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- python
- Domain
- developer-experience
Research direction
Start with the typeshed definition of class tuple and its tuple.hash method, as described in the issue. Investigate whether restricting hashing to tuples of Hashable items is sound without breaking existing code, then document a decided typing approach and validate it against relevant type-checking behavior.
Written by the indexing model from the issue text.
Description
If a tuple contains unhashable entries, hashing it would raise TypeError. Is this possible to type? Currently, tuple.__hash__ is just a regular method that returns int.
This initial idea comes to mind, but on second thought, it would likely break a lot of code:
class tuple(Sequence[_T_co]):
def __hash__(self: tuple[Hashable, ...]) -> int: ...
- Dominant language
- Python
- Stars
- 5.1k
- Forks
- 2.1k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 82
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.
More from python/typeshed
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
-
project: infrastructure
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
-
stubs: improvement
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
bancolombia/sentinel#23 ·
-
test md OpenCI
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
langchain-ai/deepagents#6450 ·
-
bug client
Difficulty 2/5 1-3 hours Newbie friendliness 88/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100