Skip to content

Possibility to type tuple.__hash__ to only accept hashable items #15851

@jonathandung

Description

@jonathandung

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions