pyrefly icon indicating copy to clipboard operation
pyrefly copied to clipboard

Inherit base method docstrings in hover when an override has no docstring

Open matuusu opened this issue 1 month ago • 4 comments

Describe the Bug

When hovering over an overridden method that has no docstring, Pyrefly does not display the docstring defined in the base class. This makes useful API documentation unavailable when navigating implementations through an LSP client.

Pyright handles this case by displaying the base method's docstring when the overridden method has none.

class SettingsProvider:
    def get_setting(self, name: str) -> str | None:
        """Return the setting value, or None if it is not configured."""
        raise NotImplementedError


class DictSettingsProvider(SettingsProvider):
    def __init__(self, settings: dict[str, str]) -> None:
        self._settings = settings

    def get_setting(self, name: str) -> str | None:
        return self._settings.get(name)


provider = DictSettingsProvider({"theme": "dark"})
provider.get_setting("theme")  # Hover over get_setting

When hovering over provider.get_setting("theme"):

  • Pyright: Displays the docstring from SettingsProvider.get_setting.
  • Pyrefly: Displays no docstring.

Expected behavior: When the resolved method has no docstring, Pyrefly should fall back to the nearest documented implementation of that method in the class's inheritance hierarchy, following Python's method resolution order (MRO).

A docstring defined directly on the overridden method should always take precedence over inherited documentation.

This would make hover documentation more useful when working with class hierarchies and avoid requiring redundant docstrings in every override.

Sandbox Link

No response

(Only applicable for extension issues) IDE Information

No response

matuusu avatar Oct 26 '26 18:10 matuusu

/claim

Sainath-Reddy7 avatar Nov 01 '26 18:11 Sainath-Reddy7

Code pointer for anyone who wants to pick this up: https://github.com/meta/pyrefly/blob/07421c64ce4c7b37365c0481f1faa0ab91a0a24a/pyrefly/lib/lsp/wasm/hover.rs#L1678-L1685

rchen152 avatar Nov 05 '26 04:11 rchen152

#claim

Quaden2307 avatar Nov 11 '26 17:11 Quaden2307

@Quaden2307 you've claimed this issue — it's now assigned to you. Thanks for picking it up! 🎉

github-actions[bot] avatar Nov 11 '26 17:11 github-actions[bot]