[ty] Remove hack in protocol satisfiability check by sharkdp · Pull Request #20568 · astral-sh/ruff (original) (raw)
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
- Adapted Markdown tests
- Made sure that this change works in combination with [ty] Use typing.Self for the first parameter of instance methods #20517
Multi-file analysis & type inference
label
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.
mypy_primer results
Changes were detected when running on open source projects
antidote (https://github.com/Finistere/antidote)
- src/antidote/lib/interface_ext/_internal.py:132:27: error[invalid-argument-type] Argument to bound method
appendis incorrect: ExpectedPredicate[Weight@create_conditions] | Weight@create_conditions | NeutralWeight | None | bool, foundQualifiedBy - src/antidote/lib/interface_ext/_internal.py:134:27: error[invalid-argument-type] Argument to bound method
appendis incorrect: ExpectedPredicate[Weight@create_conditions] | Weight@create_conditions | NeutralWeight | None | bool, foundQualifiedBy
- tests/lib/interface/test_conditions.py:193:45: error[invalid-argument-type] Argument to bound method
whenis incorrect: ExpectedPredicate[Weight | None] | Weight | None | NeutralWeight | bool, foundOnlyIf - Found 304 diagnostics
- Found 305 diagnostics
scikit-build-core (https://github.com/scikit-build/scikit-build-core)
- src/scikit_build_core/build/_wheelfile.py:51:22: error[no-matching-overload] No overload of function
fieldmatches arguments
- Found 52 diagnostics
- Found 53 diagnostics
jax (https://github.com/google/jax)
- jax/experimental/pallas/ops/gpu/attention_mgpu.py:461:9: error[invalid-argument-type] Argument to function
emit_pipeline_warp_specializedis incorrect: ExpectedComputeContext | None, founddef _compute_thread(pipeline_callback) -> Unknown - jax/experimental/pallas/ops/gpu/attention_mgpu.py:568:7: error[invalid-argument-type] Argument to function
emit_pipeline_warp_specializedis incorrect: ExpectedComputeContext | None, founddef _compute_thread(pipeline_callback) -> Unknown - jax/experimental/pallas/ops/gpu/attention_mgpu.py:755:9: error[invalid-argument-type] Argument to function
emit_pipeline_warp_specializedis incorrect: ExpectedComputeContext | None, founddef _compute_thread(pipeline_callback) -> Unknown
- Found 2251 diagnostics
- Found 2254 diagnostics
Memory usage changes were detected when running on open source projects
flake8 (https://github.com/pycqa/flake8)
memo metadata = ~6MB
memo metadata = ~5MB
sharkdp marked this pull request as ready for review
| 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sharkdp deleted the david/remove-protocol-satisfiability-hack branch
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 }})