pyrefly icon indicating copy to clipboard operation
pyrefly copied to clipboard

Don't check return type for @overload and docstring

Open dezhin opened this issue 8 months ago • 1 comments

Describe the Bug

@overload with a docstring declaration is very handy - the ellipsis is handled correctly. However, @overload combined with a docstring is not handled properly.

from typing import *

@overload
def foo(a: str) -> str:      # <-- Function declared to return `str` but is missing an explicit `return`
    """Docstring"""

@overload
def foo(a: int) -> int: ...  # This is OK

def foo(*args, **kwargs) -> Any:
    pass

Playground link.

Pyright doesn't report any errors in the code above.

Sandbox Link

No response

(Only applicable for extension issues) IDE Information

No response

dezhin avatar May 26 '25 02:05 dezhin

@overload
def foo(a: str) -> str:    
    """Docstring"""
    ... # <----

You can fix it by adding ...

nobodyoutside avatar May 28 '25 00:05 nobodyoutside