GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Consider not treating `Hashable` as equivalent to `object` · Issue #1162 · astral-sh/ty

Consider not treating Hashable as equivalent to object  #1162

New issue
Copy link
New issue
Copy link
Closed
astral-sh/ruff
#26039
astral-sh/ruff#26039
Closed
Consider not treating Hashable as equivalent to object #1162
astral-sh/ruff
#26039
Copy link
Assignees
charliermarsh
Labels
conformanceprotocolsIssues related to (typing.)Protocolsset-theoretic typesunions, intersections and more
Milestone
Stable

Description

@AlexWaygood
AlexWaygood
opened on Sep 10, 2025
Issue body actions

In astral-sh/ruff#20284, we reworked our logic so that Hashable is treated equivalently to object in subtyping and assignability checks. This is defensible from a theoretical perspective, since all instances of "exactly object" are hashable at runtime, which therefore makes object a subtype of Hashable by all normal rules of protocol assignability and subtyping. However, rules around hashability in Python do not obey the normal rules: hashable classes often inherit from unhashable ones, and unhashable classes often inherit from hashable ones, flying in the face of the Liskov Substitution Principle. Our current approach to Hashable and similar protocols makes these protocols effectively useless; we will not complain about code like this, even though users would expect us to do so (and even though other type checkers issue complaints):

from typing import Hashable

def f(x: Hashable): ...

f([])

Given that the Liskov principle is so frequently and fragrantly violated for hashability, in Python's builtin types, standard library, and across a wide range of Python code, it may be worth us seeing if we can roll back astral-sh/ruff#20284 and find another solution to #1132 that improves our compatibility with other type checkers. The reason why other type checkers do not run into problems such as #1132 is that they do not eagerly simplify unions of Hashable and other types in the same way we do. We should consider doing the same; it would probably lead to more intuitive behaviour from users' perspective, and compatibility with other type checkers is also a useful goal.

Reacted by DetachHead
Reacted by Rodrigo Girão Serrão and Niklas Mertsch

Activity

  1. AlexWaygood
    added
    wishNot on the current roadmap; maybe in the future
    set-theoretic typesunions, intersections and more
    protocolsIssues related to (typing.)Protocols
    on Sep 10, 2025
  2. carljm
    added
    needs-decisionAwaiting a decision from a maintainer
    on Nov 15, 2025
  3. carljm
    modified the milestone: This milestone has been deleted on Nov 15, 2025
  4. NMertsch commented on Feb 8, 2026

    @NMertsch
    NMertsch
    on Feb 8, 2026 · Hidden as resolved
    show commentMore actions
  5. carljm
    changed the title [-]Consider improving compatibility with other type checkers around treatment of `Hashable`[/-] [+]Consider not treating `Hashable` as equivalent to `object` [/+] on Feb 10, 2026
  6. AlexWaygood
    added
    conformance
    on Mar 20, 2026
  7. sharkdp
    removed
    needs-decisionAwaiting a decision from a maintainer
    on Apr 29, 2026
  8. sharkdp commented on Apr 29, 2026

    @sharkdp
    sharkdp
    on Apr 29, 2026
    Contributor
    More actions

    We discussed this internally and our current plan is to add a special case for Hashable, such that Hashable | C would not simplify to Hashable (unless C is @final), basically what was said in the last paragraph above, but specifically only for Hashable.

    The reason why other type checkers do not run into problems such as #1132 is that they do not eagerly simplify unions of Hashable and other types in the same way we do. We should consider doing the same; it would probably lead to more intuitive behaviour from users' perspective, and compatibility with other type checkers is also a useful goal.

    Reacted by Aleksandr Slepchenkov
  9. sharkdp
    added this to the Stable milestone on Apr 29, 2026
  10. carljm
    removed
    wishNot on the current roadmap; maybe in the future
    on Apr 29, 2026
  11. charliermarsh
    assigned
    charliermarsh
    and unassigned
    charliermarsh
    on Jun 16, 2026
  12. charliermarsh
    closed this as completedin ruff#26039on Jun 17, 2026
  13. charliermarsh
    added a commit that references this issue on Jun 17, 2026

    [ty] Preserve non-final types in Hashable unions (#26039)

    05ec34e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @charliermarsh
    charliermarsh

Labels

conformanceprotocolsIssues related to (typing.)Protocolsset-theoretic typesunions, intersections and more

Type

No type

Projects

No projects

    Milestone

    • StableNo due date

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

    You are visitor 01402792 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.