Repository navigation
[ty] Retain receiver parameters in protocol access - #28822
Merged
Merged
Conversation
Typing conformance resultsNo changes detected ✅Current numbersThe percentage of diagnostics emitted that were expected errors held steady at 98.15%. The percentage of expected errors that received a diagnostic held steady at 98.07%. The number of fully passing files held steady at 133/146. |
Memory usage reportSummary
Significant changesClick to expand detailed breakdownflake8
sphinx
trio
prefect
|
|
Merging this PR will not alter performance
Comparing Footnotes
|
sharkdp
commented
Sep 23, 2026
| ProtocolMemberKind::Method(member, kind) => { | ||
| let instance_method = match (member.ty(), kind) { | ||
| (Type::Callable(callable), ProtocolMethodKind::Instance) => member.with_ty( | ||
| Type::Callable(protocol_bind_self(db, env.program(db), callable, None)), |
Contributor
Author
There was a problem hiding this comment.
This is the eager receiver binding that we avoid with the new API.
sharkdp
commented
Sep 23, 2026
Comment on lines
+718
to
+722
| let runtime_type = if kind == ProtocolMethodKind::Class { | ||
| receiver_ty.to_meta_type(db, env) | ||
| } else { | ||
| receiver_ty | ||
| }; |
Contributor
Author
There was a problem hiding this comment.
In the former version, classmethods already had their cls receiver removed (and instance methods had self removed), so this didn't need to be computed.
dhruvmanila
approved these changes
Sep 24, 2026
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR is a refactoring that allows us to keep track of the declared receiver type for protocol members. For example, consider this protocol:
Previously, when accessing the read/write access properties of the protocol member, we would eagerly bind the
selfparameter, losing track of theself: Tannotation which is necessary to properly resolve calls to this method. With this PR, we instead retain a reference to the full generic signature[T](self: T) -> T.I made various improvements to the read/write access API, but didn't attempt to solve all problems that I saw. Also added some TODO comments.
This refactoring is in preparation for fixes to astral-sh/ty#4544 and astral-sh/ty#4075.