[ty] Retain receiver parameters in protocol access
Merged
SH
1mo ago+708+708+012345678901234567890123456789-582-582-012345678901234567890123456789
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:
from typing import Protocol
class Copyable(Protocol):
def copy[T](self: T) -> T: ...
Previously, when accessing the read/write access properties of the protocol member, we would eagerly bind the self parameter, losing track of the self: T annotation 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.