[ty] Assume type of self is typing.Self in method calls (#18007)

Part of https://github.com/astral-sh/ty/issues/159

This PR only adjusts the signature of a method so if it has a `self`
argument then that argument will have type of `Typing.Self` even if it's
not specified. If user provides an explicit annotation then Ty will not
override that annotation.

- https://github.com/astral-sh/ty/issues/1131
- https://github.com/astral-sh/ty/issues/1157
- https://github.com/astral-sh/ty/issues/1156
- https://github.com/astral-sh/ty/issues/1173
- https://github.com/astral-sh/ruff/pull/20328
- https://github.com/astral-sh/ty/issues/1163
- https://github.com/astral-sh/ty/issues/1196

Added mdtests.
Also some tests need https://github.com/astral-sh/ruff/pull/18473 to
work completely. So I added a todo for those new cases that I added.

---------

Co-authored-by: David Peter <mail@david-peter.de>
This commit is contained in:
Shaygan Hooshyari 2025-09-22 20:37:20 +02:00 committed by David Peter
parent 24fec9ac1c
commit 3062e71cff
18 changed files with 383 additions and 103 deletions

View file

@ -3030,6 +3030,12 @@ impl Parameters {
.find(|arg| arg.parameter.name.as_str() == name)
}
/// Returns the index of the parameter with the given name
pub fn index(&self, name: &str) -> Option<usize> {
self.iter_non_variadic_params()
.position(|arg| arg.parameter.name.as_str() == name)
}
/// Returns an iterator over all parameters included in this [`Parameters`] node.
pub fn iter(&self) -> ParametersIterator<'_> {
ParametersIterator::new(self)