Skip to content

Conversation

@RasmusNygren
Copy link
Contributor

@RasmusNygren RasmusNygren commented Nov 20, 2025

Statements such as def foo(p<CURSOR>,
def foo[T<CURSOR> and for foo<CURSOR>
should not generate any suggestions as these
cases are introducing new names.

If it's not possible to determine that suggestions should be omitted using token matching in an easy way, we turn
to traversing the AST to determine the context.

Summary

Fixes astral-sh/ty#1563

It keeps using the existing token matching pattern for the easy cases (nothing typed and most recent token is a definition token) and fallbacks to AST traveral for the slightly more difficult cases where token matching becomes difficult and error prone.

Test Plan

New test cases and sanity-checking in the ty playground

Statements such as `def foo(p<CURSOR>`,
`def foo[T<CURSOR>` and `for foo<CURSOR>`
should not generate any suggestions as these
cases are introducing new names.

If it's not possible to determine that suggestions
should be omitted using token matching, we turn
to traversing the AST to determine the context.
@MichaReiser MichaReiser requested review from BurntSushi and removed request for AlexWaygood, carljm, dcreager and sharkdp November 20, 2025 21:51
@RasmusNygren RasmusNygren force-pushed the suppress-suggestions-when-naming branch from 9ac8690 to 23fa8f5 Compare November 20, 2025 21:52
@AlexWaygood AlexWaygood added server Related to the LSP server ty Multi-file analysis & type inference labels Nov 20, 2025
@AlexWaygood AlexWaygood changed the title [ty] suppress suggestions during variable binding [ty] suppress autocomplete suggestions during variable binding Nov 20, 2025
@astral-sh-bot
Copy link

astral-sh-bot bot commented Nov 20, 2025

Diagnostic diff on typing conformance tests

No changes detected when running ty on typing conformance tests ✅

@astral-sh-bot
Copy link

astral-sh-bot bot commented Nov 20, 2025

mypy_primer results

Changes were detected when running on open source projects
scikit-build-core (https://github.com/scikit-build/scikit-build-core)
- src/scikit_build_core/build/wheel.py:98:20: error[no-matching-overload] No overload of bound method `__init__` matches arguments
- Found 44 diagnostics
+ Found 43 diagnostics

No memory usage changes detected ✅

Copy link
Member

@BurntSushi BurntSushi left a comment

Choose a reason for hiding this comment

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

Nice, this makes sense to me!

@BurntSushi BurntSushi merged commit 03dfbf2 into astral-sh:main Nov 21, 2025
43 checks passed
@BurntSushi
Copy link
Member

Thank you!!!

BurntSushi added a commit that referenced this pull request Nov 21, 2025
PR #21549 introduced a subtle overflow bug that seemed impossible, but
can empirically happen. This PR fixes it by saturating to zero.

I did try to write a regression test for this, but couldn't manage it.
Instead, I'll attach before-and-after screen recordings.
BurntSushi added a commit that referenced this pull request Nov 21, 2025
PR #21549 introduced a subtle overflow bug that seemed impossible, but
can empirically happen. This PR fixes it by saturating to zero.

I did try to write a regression test for this, but couldn't manage it.
Instead, I'll attach before-and-after screen recordings.
BurntSushi added a commit that referenced this pull request Nov 21, 2025
PR #21549 introduced a subtle overflow bug that seemed impossible, but
can empirically happen. This PR fixes it by saturating to zero.

I did try to write a regression test for this, but couldn't manage it.
Instead, I'll attach before-and-after screen recordings.
dcreager added a commit that referenced this pull request Nov 24, 2025
…d-typevar

* origin/main: (24 commits)
  [ty] Remove brittle constraint set reveal tests (#21568)
  [`ruff`] Catch more dummy variable uses (`RUF052`) (#19799)
  [ty] Use the same snapshot handling as other tests (#21564)
  [ty] suppress autocomplete suggestions during variable binding (#21549)
  Set severity for non-rule diagnostics (#21559)
  [ty] Add `with_type` convenience to display code (#21563)
  [ty] Implement docstring rendering to markdown (#21550)
  [ty] Reduce indentation of `TypeInferenceBuilder::infer_attribute_load` (#21560)
  Bump 0.14.6 (#21558)
  [ty] Improve debug messages when imports fail (#21555)
  [ty] Add support for relative import completions
  [ty] Refactor detection of import statements for completions
  [ty] Use dedicated collector for completions
  [ty] Attach subdiagnostics to `unresolved-import` errors for relative imports as well as absolute imports (#21554)
  [ty] support PEP 613 type aliases (#21394)
  [ty] More low-hanging fruit for inlay hint goto-definition (#21548)
  [ty] implement `TypedDict` structural assignment (#21467)
  [ty] Add more random TypeDetails and tests (#21546)
  [ty] Add goto for `Unknown` when it appears in an inlay hint (#21545)
  [ty] Add type definitions for `Type::SpecialForm`s (#21544)
  ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

server Related to the LSP server ty Multi-file analysis & type inference

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Completions should be suppressed in for foo<CURSOR>, def foo(param<CURSOR> and def foo[T<CURSOR>]

3 participants