[ty] Remove hack in protocol satisfiability check by sharkdp · Pull Request #20568 · astral-sh/ruff (original) (raw)

@sharkdp

Summary

This removes a hack in the protocol satisfiability check that was previously needed to work around missing assignability-modeling of inferable type variables. Assignability of type variables is not implemented fully, but some recent changes allow us to remove that hack with limited impact on the ecosystem (and the test suite). The change in the typing conformance test is favorable.

Test Plan

@sharkdp sharkdp added the ty

Multi-file analysis & type inference

label

Sep 25, 2025

@github-actions

Diagnostic diff on typing conformance tests

Changes were detected when running ty on typing conformance tests

--- old-output.txt 2025-09-25 11:25:37.323644940 +0000 +++ new-output.txt 2025-09-25 11:25:40.505639553 +0000 @@ -430,6 +430,7 @@ generics_self_basic.py:75:5: error[type-assertion-failure] Argument does not have asserted type Container[str] generics_self_basic.py:83:5: error[type-assertion-failure] Argument does not have asserted type Container[T@object_with_generic_type] generics_self_protocols.py:48:5: error[type-assertion-failure] Argument does not have asserted type ShapeProtocol +generics_self_protocols.py:61:19: error[invalid-argument-type] Argument to function accepts_shape is incorrect: Expected ShapeProtocol, found BadReturnType generics_self_usage.py:73:14: error[invalid-type-form] Variable of type typing.Self is not allowed in a type expression generics_self_usage.py:73:23: error[invalid-type-form] Variable of type typing.Self is not allowed in a type expression generics_self_usage.py:76:6: error[invalid-type-form] Variable of type typing.Self is not allowed in a type expression @@ -860,5 +861,5 @@ typeddicts_usage.py:28:17: error[missing-typed-dict-key] Missing required key 'name' in TypedDict Movie constructor typeddicts_usage.py:28:18: error[invalid-key] Invalid key access on TypedDict Movie: Unknown key "title" typeddicts_usage.py:40:24: error[invalid-type-form] The special form typing.TypedDict is not allowed in type expressions. Did you mean to use a concrete TypedDict or collections.abc.Mapping[str, object] instead? -Found 861 diagnostics +Found 862 diagnostics WARN A fatal error occurred while checking some files. Not all project files were analyzed. See the diagnostics list above for details.

@github-actions

mypy_primer results

Changes were detected when running on open source projects

antidote (https://github.com/Finistere/antidote)

scikit-build-core (https://github.com/scikit-build/scikit-build-core)

jax (https://github.com/google/jax)

Memory usage changes were detected when running on open source projects

flake8 (https://github.com/pycqa/flake8)

@sharkdp

@sharkdp sharkdp marked this pull request as ready for review

September 25, 2025 10:58

sharkdp

class NewStyleClassScoped[T](Protocol):
def method(self, input: T) -> None: ...
def method(self: Self, input: T) -> None: ...

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I can remove these Self annotations again in the type-of-self PR.

AlexWaygood

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sharkdp

@sharkdp

@sharkdp sharkdp deleted the david/remove-protocol-satisfiability-hack branch

September 25, 2025 11:35

This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.Learn more about bidirectional Unicode characters

[ Show hidden characters]({{ revealButtonHref }})