ruff/crates/ty_python_semantic/resources/mdtest
Shaygan Hooshyari d566636ca5
Some checks are pending
CI / cargo fmt (push) Waiting to run
CI / Determine changes (push) Waiting to run
CI / cargo clippy (push) Blocked by required conditions
CI / cargo test (linux) (push) Blocked by required conditions
CI / cargo test (linux, release) (push) Blocked by required conditions
CI / cargo test (windows) (push) Blocked by required conditions
CI / cargo test (wasm) (push) Blocked by required conditions
CI / cargo build (release) (push) Waiting to run
CI / cargo build (msrv) (push) Blocked by required conditions
CI / cargo fuzz build (push) Blocked by required conditions
CI / fuzz parser (push) Blocked by required conditions
CI / test scripts (push) Blocked by required conditions
CI / ecosystem (push) Blocked by required conditions
CI / Fuzz for new ty panics (push) Blocked by required conditions
CI / cargo shear (push) Blocked by required conditions
CI / python package (push) Waiting to run
CI / pre-commit (push) Waiting to run
CI / mkdocs (push) Waiting to run
CI / formatter instabilities and black similarity (push) Blocked by required conditions
CI / test ruff-lsp (push) Blocked by required conditions
CI / check playground (push) Blocked by required conditions
CI / benchmarks (push) Blocked by required conditions
[ty Playground] Release / publish (push) Waiting to run
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
..
annotations Support typing.Self in methods (#17689) 2025-05-07 15:58:00 -07:00
assignment
binary Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
boolean
boundness_declaredness Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
call Support typing.Self in methods (#17689) 2025-05-07 15:58:00 -07:00
class Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
comparison
comprehensions
conditional
declaration
diagnostics
directives
doc
exception Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
expression Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
function [ty] Recognise functions containing yield from expressions as being generator functions (#17930) 2025-05-07 23:29:44 +01:00
generics [ty] Check base classes when determining subtyping etc for generic aliases (#17927) 2025-05-07 15:21:11 -04:00
import [ty] Add support for __all__ (#17856) 2025-05-07 21:42:42 +05:30
literal
loops
narrow Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
regression
scopes Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
shadowing
snapshots [ty] Recognise functions containing yield from expressions as being generator functions (#17930) 2025-05-07 23:29:44 +01:00
stubs Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
subscript Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
suppressions
type_of Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
type_properties [ty] Check base classes when determining subtyping etc for generic aliases (#17927) 2025-05-07 15:21:11 -04:00
type_qualifiers
unary Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
with
.mdformat.toml
attributes.md Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
cycle.md [ty] add cycle handling for FunctionType::signature query (#17833) 2025-05-05 12:12:38 -07:00
dataclass_transform.md [ty] Detect overloads decorated with @dataclass_transform (#17835) 2025-05-07 15:51:13 +02:00
dataclasses.md Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
decorators.md [ty] Specialize bound methods and nominal instances (#17865) 2025-05-05 17:17:36 -04:00
descriptor_protocol.md Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
final.md
intersection_types.md
invalid_syntax.md
known_constants.md
mdtest_config.md
mdtest_custom_typeshed.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
metaclass.md Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
mro.md [ty] Improve UX for [duplicate-base] diagnostics (#17914) 2025-05-07 15:27:37 +00:00
named_tuple.md
overloads.md
pep695_type_aliases.md
properties.md
protocols.md [ty] Protocols: Fixpoint iteration for fully-static check (#17880) 2025-05-07 08:55:21 +02:00
slots.md
statically_known_branches.md
sys_platform.md
sys_version_info.md
terminal_statements.md
type_api.md Update class literal display to use <class 'Foo'> style (#17889) 2025-05-06 20:11:25 -04:00
typed_dict.md
union_types.md
unpacking.md
unreachable.md