Repository navigation
Fix docstring fallback on hover for matched overload without docstring - #12045
Vishal Raj (vishalrajofficial) wants to merge 3 commits into
Conversation
Signed-off-by: Vishal Raj <9031842908.vk@gmail.com>
|
🤖 AI-assisted review posted on behalf of Bill Schnurr (@bschnurr) I found a signature-help regression and an inherited-hover case that still shows an unrelated overload's documentation. Regression: constructor signature help loses the matching from typing import overload
class NewDocs:
@overload
def __init__(self, x: int) -> None: ...
@overload
def __init__(self, x: str) -> None: ...
def __init__(self, x: int | str) -> None: pass
@overload
def __new__(cls, x: int) -> "NewDocs":
"""new integer docs"""
@overload
def __new__(cls, x: str) -> "NewDocs":
"""new string docs"""
def __new__(cls, x: int | str) -> "NewDocs":
return super().__new__(cls)
NewDocs(1) # Request signature help at the argument.On Existing gap: inherited overloads can still supply the wrong documentation. from typing import overload
class Base:
@overload
def method(self, x: int) -> int:
"""integer docs"""
@overload
def method(self, x: str) -> str: ...
def method(self, x: int | str) -> int | str:
return x
class Derived(Base):
@overload
def method(self, x: int) -> int: ...
@overload
def method(self, x: str) -> str: ...
def method(self, x: int | str) -> int | str:
return x
Derived().method("") # Hover over method.Both revisions show Could the guard distinguish hints from a different constructor member, and avoid borrowing an unrelated inherited overload? Focused signature-help and inherited-hover tests would cover both paths. |
…d overload - Scope memberName check so hints from a different constructor member do not suppress fallback overloads - Forward matched overload hint in base class resolution to avoid borrowing unrelated inherited sibling overloads - Add focused FourSlash tests for constructor signature help and inherited method hover Signed-off-by: Vishal Raj <9031842908.vk@gmail.com>
|
Thanks for the thorough review and edge cases Bill Schnurr (@bschnurr)! I have addressed both issues in commit b12aabf:
|
- Correlate corresponding overload signatures across inheritance and between constructor members (__init__ and __new__) using callable parameter matching - Only suppress Tier 3 fallback when matchedOverloads is a narrowed subset and matches a member overload, preserving docstring inheritance on uncalled hover and completion Signed-off-by: Vishal Raj <9031842908.vk@gmail.com>
Summary
Fixes #12042.
When hovering over an overloaded function call site, hover information should display the docstring of the matched overload or fall back to the function implementation docstring. Previously, if the matched overload had no docstring and the implementation had no docstring,
_selectMemberDocInfofell through to Tier 3, returning the docstring of the first sibling overload in declaration order. This caused calls matching an undocumented overload (such asfun(b"")) to display an unrelated overload's docstring (such as"int overload").This change ensures Tier 3 (evaluating other overloads in declaration order) only runs when no specific overload was matched for the reference (e.g. uncalled function hover).
Evidence and validation
Added focused fourslash regression coverage in
packages/pyright-internal/src/tests/fourslash/hover.overloadedFunction.docstring.fourslash.tscovering:fun(1),fun(""))fun(b"")), verifying it does not display the first overload's docstringfun), verifying it falls back to the declared overload docstringRan fourslash tests locally:
node ./node_modules/jest/bin/jest src/tests/fourSlashRunner.test.ts -t "hover\." --forceExit(52 passed)Ran lint and format checks:
eslint(0 errors),prettier(clean)