Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[ty] Fix goto-definiton for self-imported sub-modules#25106

Merged
MichaReiser merged 1 commit into
mainfrom
micha/self-import
May 13, 2026
Merged

[ty] Fix goto-definiton for self-imported sub-modules#25106
MichaReiser merged 1 commit into
mainfrom
micha/self-import

Conversation

@MichaReiser

@MichaReiser MichaReiser commented May 11, 2026

Copy link
Copy Markdown
Member

Summary

Fixes goto-definition for imports that self-reference the current module:

__init__.py

from . import ops # can't click to go to module file
from . import xyz # can't click to go to module file

Resolving ops requires resolving . to __init__.py. Go-to definition then looks for a ops symbol within __init__.py, before trying to resolve ops as a submodule. However, go-to def now finds the same definition again as it started from (the ops import from .), which it then tries to resolve that again. The recursion handler catches this and empty result.

This PR catches this and, instead of returning an empty result, returns any available sub module

Fixes astral-sh/ty#2907

@MichaReiser MichaReiser added bug Something isn't working server Related to the LSP server ty Multi-file analysis & type inference labels May 11, 2026
@astral-sh-bot

astral-sh-bot Bot commented May 11, 2026

Copy link
Copy Markdown

Typing conformance results

No changes detected ✅

Current numbers
The percentage of diagnostics emitted that were expected errors held steady at 89.36%. The percentage of expected errors that received a diagnostic held steady at 85.49%. The number of fully passing files held steady at 88/134.

@astral-sh-bot

astral-sh-bot Bot commented May 11, 2026

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@astral-sh-bot

astral-sh-bot Bot commented May 11, 2026

Copy link
Copy Markdown

ecosystem-analyzer results

No diagnostic changes detected ✅

Full report with detailed diff (timing results)

@MichaReiser MichaReiser marked this pull request as ready for review May 11, 2026 16:25
@astral-sh-bot astral-sh-bot Bot requested a review from dhruvmanila May 11, 2026 16:25
@MichaReiser MichaReiser merged commit 3ebf2f1 into main May 13, 2026
58 checks passed
@MichaReiser MichaReiser deleted the micha/self-import branch May 13, 2026 12:32
thejchap pushed a commit to thejchap/ruff that referenced this pull request May 23, 2026
## Summary

Fixes goto-definition for imports that self-reference the current
module:

`__init__.py`

```py
from . import ops # can't click to go to module file
from . import xyz # can't click to go to module file
```

Resolving `ops` requires resolving `.` to `__init__.py`. Go-to
definition then looks for a `ops` symbol within `__init__.py`, before
trying to resolve `ops` as a submodule. However, go-to def now finds the
same definition again as it started from (the `ops` import from `.`),
which it then tries to resolve that again. The recursion handler catches
this and empty result.

This PR catches this and, instead of returning an empty result, returns
any available sub module

Fixes astral-sh/ty#2907
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working 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.

Relative import resolution

2 participants