Visitar URL original
[ty] Assign lower completions ranking to deprecated functions and classes by Glyphack · Pull Request #23089 · astral-sh/ruff · GitHub
Skip to content

[ty] Assign lower completions ranking to deprecated functions and classes - #23089

Merged
BurntSushi merged 2 commits into
astral-sh:mainfrom
Glyphack:deprecated-autocmp
Feb 9, 2026
Merged

BurntSushi merged 2 commits into
astral-sh:mainfrom
Glyphack:deprecated-autocmp

Conversation

@Glyphack

@Glyphack Glyphack commented Feb 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

This makes the completion rank deprecated functions and classes lower than non deprecated ones. It relies on the @deprecated decorator on the definition.

I'm new to this subsystem. Let me know if something should be done differently.

Fixes astral-sh/ty#2654

Test Plan

Added completion eval test.

@astral-sh-bot

astral-sh-bot Bot commented Feb 5, 2026 •

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

@astral-sh-bot

astral-sh-bot Bot commented Feb 5, 2026 •

Copy link
Copy Markdown

mypy_primer results

Changes were detected when running on open source projects
porcupine (https://github.com/Akuli/porcupine)
- porcupine/pluginmanager.py:133:49: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Iterable[Never]`, found `Unknown | str`
- Found 25 diagnostics
+ Found 24 diagnostics

setuptools (https://github.com/pypa/setuptools)
+ setuptools/_distutils/command/install.py:719:42: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Iterable[Never]`, found `map[str]`
- Found 1138 diagnostics
+ Found 1139 diagnostics

prefect (https://github.com/PrefectHQ/prefect)
- src/prefect/input/run_input.py:672:20: error[invalid-return-type] Return type does not match returned value: expected `T@GetAutomaticInputHandler | AutomaticRunInput[T@GetAutomaticInputHandler]`, found `T@GetAutomaticInputHandler | AutomaticRunInput[T@GetAutomaticInputHandler] | Coroutine[Any, Any, T@GetAutomaticInputHandler | AutomaticRunInput[T@GetAutomaticInputHandler]]`
+ src/prefect/input/run_input.py:672:20: error[invalid-return-type] Return type does not match returned value: expected `T@GetAutomaticInputHandler | AutomaticRunInput[T@GetAutomaticInputHandler]`, found `Unknown | Coroutine[Any, Any, Unknown]`

materialize (https://github.com/MaterializeInc/materialize)
- misc/python/materialize/cli/mz_workload_anonymize.py:251:13: error[no-matching-overload] No overload of bound method `join` matches arguments
- Found 535 diagnostics
+ Found 534 diagnostics

sympy (https://github.com/sympy/sympy)
- sympy/parsing/mathematica.py:692:38: error[invalid-argument-type] Argument to function `__new__` is incorrect: Expected `Iterable[Never]`, found `Unknown | list[Unknown | str]`
- Found 15901 diagnostics
+ Found 15900 diagnostics

No memory usage changes detected ✅

@ntBre ntBre added the ty The ty type checker label Feb 5, 2026
@AlexWaygood AlexWaygood added the server Related to the Ruff or ty LSP server label Feb 5, 2026
@AlexWaygood AlexWaygood changed the title [ty] Assign lower rank to deprecated functions and classes [ty] Assign lower completions ranking to deprecated functions and classes Feb 5, 2026
@Glyphack
Glyphack marked this pull request as ready for review February 5, 2026 16:06

@BurntSushi BurntSushi left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM with a nit.

Note that this doesn't handle the auto-import case, which will require parsing out the @deprecated decorator explicitly (auto-import doesn't have access to ty's type information). But I think this PR is an improvement on the status quo. It doesn't need to handle the auto-import case. But we shouldn't close astral-sh/ty#2654 yet.

Comment thread crates/ty_ide/src/completion.rs Resolved
This makes the completion rank deprecated functions and classes lower
than non deprecated ones. It relies on the `@deprecated` decorator on the definition.

Fixes astral-sh/ty#2654
@Glyphack

Glyphack commented Feb 5, 2026 •

Copy link
Copy Markdown
Contributor Author

Thanks for letting me know I'll look into the auto import case tomorrow and send another PR.

@sharkdp
sharkdp removed their request for review February 6, 2026 10:31
@BurntSushi
BurntSushi merged commit 94c41ed into astral-sh:main Feb 9, 2026
50 checks passed
@Glyphack
Glyphack deleted the deprecated-autocmp branch February 9, 2026 21:08
carljm added a commit to Hugo-Polloli/ruff that referenced this pull request Feb 9, 2026
* main: (45 commits)
  [ty] Fix wrong inlay hints for overloaded function arguments (astral-sh#23179)
  [ty] Respect `@no_type_check` when combined with other decorators (astral-sh#23177)
  [ty] Use type context when inferring constructor argument types (astral-sh#23139)
  [`airflow`] Add ruff rules to catch deprecated attribute access from context key for Airflow 3.0 (`AIR301`) (astral-sh#22850)
  Support formatting `pycon` markdown code blocks (astral-sh#23112)
  Markdown formatting in LSP (astral-sh#23063)
  Instruct Claude to use comments more sparingly (astral-sh#23181)
  [`flake8-gettext`] Fix false negatives for plural argument of ngettext (`INT001`, `INT002`, `INT003`) (astral-sh#21078)
  [ty] Invoking goto-def on parentheses of a class constructor call takes you too constructor method
  [ty] Make goto definition on class constructor always go to class definition
  [ty] Assign lower completions ranking to deprecated functions and classes (astral-sh#23089)
  [ty] Fix parameter references across files via keyword args (astral-sh#23012)
  [ty] Exclude enclosing class for base completions (astral-sh#23141)
  [`pyupgrade`] Fix syntax error on string with newline escape and comment (`UP037`) (astral-sh#22968)
  [ty] Improve documentation for `expect_single_definition` method (astral-sh#23175)
  [ty] Configure check mode for all projects
  Add `home-assistant` to ecosystem projects (astral-sh#23132)
  Add tabbed shell completion documentation (astral-sh#23169)
  Bump typing conformance-suite pin (astral-sh#23174)
  [ty] Fix invalid diagnostic location for a sub-call to a specialized ParamSpec (astral-sh#23036)
  ...
BurntSushi pushed a commit that referenced this pull request Feb 11, 2026
…23188)

<!--
Thank you for contributing to Ruff/ty! To help us out with reviewing,
please consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title? (Please prefix
with `[ty]` for ty pull
  requests.)
- Does this pull request include references to any relevant issues?
-->

## Summary

Follow up to #23089 this PR
assigns lower completion ranking to deprecated names in auto import
suggestions.
The implementation relies on finding a decorator named `deprecated` in
the source code ton consider that name deprecated.

Fixes astral-sh/ty#2654 for real :)

<!-- What's the purpose of the change? What does it do, and why? -->

## Test Plan

Added another test case for this.

I could not find an 

Here's how the behavior changed:

Before:

abstractc<CURSOR>
```
AbstractAsyncContextManager (module: contextlib)
AbstractBasicAuthHandler (module: urllib.request)
AbstractChildWatcher (module: asyncio)
AbstractContextManager (module: contextlib)
AbstractEventLoopPolicy (module: asyncio)
abstractclassmethod (module: abc)
abstractstaticmethod (module: abc)
```

After:

```
AbstractAsyncContextManager (module: contextlib)
AbstractBasicAuthHandler (module: urllib.request)
AbstractContextManager (module: contextlib) (*, 3/7)
AbstractEventLoopPolicy (module: asyncio)
AbstractChildWatcher (module: asyncio)
abstractclassmethod (module: abc)
abstractstaticmethod (module: abc)
```

<!-- How was it tested? -->
KotlinIsland pushed a commit to KotlinIsland/basedpython that referenced this pull request May 1, 2026
…23188)

<!--
Thank you for contributing to Ruff/ty! To help us out with reviewing,
please consider the following:

- Does this pull request include a summary of the change? (See below.)
- Does this pull request include a descriptive title? (Please prefix
with `[ty]` for ty pull
  requests.)
- Does this pull request include references to any relevant issues?
-->

## Summary

Follow up to astral-sh/ruff#23089 this PR
assigns lower completion ranking to deprecated names in auto import
suggestions.
The implementation relies on finding a decorator named `deprecated` in
the source code ton consider that name deprecated.

Fixes astral-sh/ty#2654 for real :)

<!-- What's the purpose of the change? What does it do, and why? -->

## Test Plan

Added another test case for this.

I could not find an 

Here's how the behavior changed:

Before:

abstractc<CURSOR>
```
AbstractAsyncContextManager (module: contextlib)
AbstractBasicAuthHandler (module: urllib.request)
AbstractChildWatcher (module: asyncio)
AbstractContextManager (module: contextlib)
AbstractEventLoopPolicy (module: asyncio)
abstractclassmethod (module: abc)
abstractstaticmethod (module: abc)
```

After:

```
AbstractAsyncContextManager (module: contextlib)
AbstractBasicAuthHandler (module: urllib.request)
AbstractContextManager (module: contextlib) (*, 3/7)
AbstractEventLoopPolicy (module: asyncio)
AbstractChildWatcher (module: asyncio)
abstractclassmethod (module: abc)
abstractstaticmethod (module: abc)
```

<!-- How was it tested? -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

server Related to the Ruff or ty LSP server ty The ty type checker

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[completions] Down-rank deprecated symbols

4 participants