Skip to content

[ty] Group overloaded methods like overloaded functions for docstrings - #23920

Merged
charliermarsh merged 13 commits into
mainfrom
charlie/hover-doc
Apr 17, 2026
Merged

charliermarsh merged 13 commits into
mainfrom
charlie/hover-doc

Conversation

@charliermarsh

@charliermarsh charliermarsh commented Mar 12, 2026 •

Copy link
Copy Markdown
Member

Summary

Previously, attribute lookup for methods stopped after the first matching definition in the first matching class scope. That meant overloaded methods often resolved to just an overload declaration, which usually has no docstring... while overloaded free functions could still surface the implementation docstring.

Closes astral-sh/ty#3024.

@astral-sh-bot astral-sh-bot Bot added the ty The ty type checker label Mar 12, 2026
@astral-sh-bot

astral-sh-bot Bot commented Mar 12, 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 87.94%. The percentage of expected errors that received a diagnostic held steady at 83.36%. The number of fully passing files held steady at 79/133.

@astral-sh-bot

astral-sh-bot Bot commented Mar 12, 2026 •

Copy link
Copy Markdown

mypy_primer results

No ecosystem changes detected ✅

@astral-sh-bot

astral-sh-bot Bot commented Mar 12, 2026 •

Copy link
Copy Markdown

Memory usage report

Memory usage unchanged ✅

@charliermarsh
charliermarsh marked this pull request as ready for review March 13, 2026 02:08
@charliermarsh
charliermarsh marked this pull request as draft March 13, 2026 02:08
@charliermarsh
charliermarsh marked this pull request as ready for review March 13, 2026 02:11
@carljm
carljm removed their request for review March 13, 2026 02:26
@AlexWaygood AlexWaygood added the server Related to the Ruff or ty LSP server label Mar 13, 2026
Comment thread crates/ty_python_semantic/src/types/ide_support.rs Outdated
Comment thread crates/ty_ide/src/rename.rs Outdated
Comment thread crates/ty_python_semantic/src/types/ide_support.rs Outdated
@AlexWaygood
AlexWaygood removed their request for review March 13, 2026 10:16
@charliermarsh
charliermarsh marked this pull request as draft March 13, 2026 14:27
@charliermarsh
charliermarsh force-pushed the charlie/hover-doc branch 2 times, most recently from bd71b71 to afb5ed1 Compare March 13, 2026 15:00
@charliermarsh
charliermarsh marked this pull request as ready for review March 13, 2026 20:07
@astral-sh-bot
astral-sh-bot Bot requested a review from MichaReiser March 13, 2026 20:07
@charliermarsh

Copy link
Copy Markdown
Member Author

After adding the suggested tests, I had to revise the implementation a bit since it surfaced some issues -- sorry for the churn.

@sharkdp
sharkdp removed their request for review March 16, 2026 08:52
Comment thread crates/ty_ide/src/hover.rs Outdated
Comment thread crates/ty_python_semantic/src/types/ide_support.rs
Comment thread crates/ty_python_semantic/src/types/ide_support.rs Outdated
Comment thread crates/ty_ide/src/hover.rs Outdated

let docs = if typed_dict_key.is_some() {
None
} else if let GotoTarget::Call { callable, call, .. } = goto_target {

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.

Can you say more why you think it's preferred to handle overloads here vs in get_definition_targets as I did in #21920 ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Here, we want to return the precise overload that matches the currently-provided arguments. So we actually need to match on the arguments provided to the call. That seems a bit different than what you're doing in get_definition_targets, unless I'm misunderstanding.

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.

I never managed to finish this, but my thinking was that we want an option to parametrize go_to_definition_targets with what we're resolving: Is it definitions, declarations, exact definition etc. But given that this isn't in place today and i remember that I ran into some issues with it (which is why the PR is still in draft), I think it's okay to go with your current approach and I can revisit it in #21920.

@charliermarsh
charliermarsh marked this pull request as draft April 16, 2026 14:04
@charliermarsh
charliermarsh force-pushed the charlie/hover-doc branch 4 times, most recently from 1eb110b to 3e89515 Compare April 16, 2026 15:09
&model,
ty_python_semantic::ImportAliasResolution::ResolveAliases,
)
.and_then(|definitions| definitions.docstring(db))

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

This is different than signature help, where we want to make sure implementation and docstring are 1:1.

@charliermarsh
charliermarsh marked this pull request as ready for review April 17, 2026 00:22
Comment on lines +1491 to +1492
/// When the resolved overload has no docstring and neither does the
/// implementation, we fall back to showing a sibling overload's docstring.

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.

This is something where Pylance is inconsistent. Their signature help does show "a second overload" but hover doesn't. I don't feel strongly whether we should have this fallback, for as long as it is consistent (which we are :))

@charliermarsh
charliermarsh merged commit 6e4eca1 into main Apr 17, 2026
56 checks passed
@charliermarsh
charliermarsh deleted the charlie/hover-doc branch April 17, 2026 11:36
AlexWaygood pushed a commit that referenced this pull request Apr 17, 2026
#23920)

## Summary

Previously, attribute lookup for methods stopped after the first
matching definition in the first matching class scope. That meant
overloaded methods often resolved to just an overload declaration, which
usually has no docstring... while overloaded free functions could still
surface the implementation docstring.

Closes astral-sh/ty#3024.
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.

Docstring missing on @overload methods (but not plain functions)

3 participants