ruff/crates/ty_python_semantic/resources/mdtest/call
Shaygan Hooshyari d566636ca5
Support typing.Self in methods (#17689)
## Summary

Fixes: astral-sh/ty#159 

This PR adds support for using `Self` in methods.
When the type of an annotation is `TypingSelf` it is converted to a type
var based on:
https://typing.python.org/en/latest/spec/generics.html#self

I just skipped Protocols because it had more problems and the tests was
not useful.
Also I need to create a follow up PR that implicitly assumes `self`
argument has type `Self`.

In order to infer the type in the `in_type_expression` method I needed
to have scope id and semantic index available. I used the idea from
[this PR](https://github.com/astral-sh/ruff/pull/17589/files) to pass
additional context to this method.
Also I think in all places that `in_type_expression` is called we need
to have this context because `Self` can be there so I didn't split the
method into one version with context and one without.

## Test Plan

Added new tests from spec.

---------

Co-authored-by: Micha Reiser <micha@reiser.io>
Co-authored-by: Carl Meyer <carl@astral.sh>
2025-05-07 15:58:00 -07:00
..
annotation.md Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
builtins.md Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
callable_instance.md Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
constructor.md Support typing.Self in methods (#17689) 2025-05-07 15:58:00 -07:00
dunder.md Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
function.md Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
getattr_static.md Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
invalid_syntax.md Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
methods.md Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
never.md Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
str_startswith.md Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
subclass_of.md Rename Red Knot (#17820) 2025-05-03 19:49:15 +02:00
union.md [ty] Fix duplicate diagnostics for unresolved module when an import from statement imports multiple members (#17886) 2025-05-06 12:37:10 +01:00