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

Commit
33 days ago
[ty] Preserve non-final types in Hashable unions (#26039) ## Summary In https://github.com/astral-sh/ty/issues/1162#issuecomment-4343373191, we decided to stop simplifying `Hashable | C` to `Hashable` when `C` is non-final. A subclass can disable hashing even when its base class satisfies `Hashable`, so the existing normalization can discard a meaningful union arm: ```python from collections.abc import Hashable, Sequence def f(value: Hashable | Sequence[Hashable]) -> None: ... ``` This recognizes the standard-library protocol through both `typing.Hashable` and `collections.abc.Hashable`, and preserves the non-final arm while retaining the existing simplification for final classes and `object`. This PR uses a relatively narrow / conservative model for determining hashability; https://github.com/astral-sh/ruff/pull/26040 is more expansive, but I think it deserves to be reviewed separately. Closes https://github.com/astral-sh/ty/issues/1162.
Author
Parents
Loading