griffe icon indicating copy to clipboard operation
griffe copied to clipboard

bug: Overload only stubs are not detected

Open iatkinson opened this issue 3 months ago • 6 comments

This appears related to https://github.com/mkdocstrings/griffe/issues/116 (but is different as there is no concrete implementation here)

Description of the bug

When using stubs only, overloads do not get detected.

To Reproduce

# my_stub/__init__.py

from typing import overload

@overload
def foo(a: int) -> int: ...

@overload
def foo(a: str) -> str: ...


@overload
def bar(a: int) -> int: ...

@overload
def bar(a: str) -> str: ...

# This shoudn't be in the stub file, but without it Griffe does not detect the function.
def bar(a: int | str) -> int | str: ...
>>> griffe.load('my_stub').members
{'overload': Alias('overload', 'typing.overload'), 'bar': Function('bar', 18, 18)}

bar is detected but not foo in the stub.

Expected behavior

Expect foo in the above stub to be detected.

Environment information

griffe==1.14.0

Note

Using a stub-only package for doc generation using mkdocstrings to avoid pulling all dependencies of the full package.

iatkinson avatar Oct 05 '25 21:10 iatkinson

Thanks for the report @iatkinson. I guess we could fake the implementation when it isn't found, so that overloads get attached to it, and you'd use relevant options in mkdocstrings to only show the overloads and not the (fake) implementation signature 🤔

pawamoy avatar Oct 05 '25 23:10 pawamoy

avoid pulling all dependencies of the full package

That's not needed by the way, you could install just the package without its dependencies.

pawamoy avatar Oct 05 '25 23:10 pawamoy

Also, if we want to follow the spec, you'd have to use the .pyi extension, and name your package foopkg-stubs. But we can consider being more lax than type-checkers on this.

pawamoy avatar Oct 05 '25 23:10 pawamoy

Also, if we want to follow the spec, you'd have to use the .pyi extension, and name your package foopkg-stubs. But we can consider being more lax than type-checkers on this.

Yeah, it should be a .pyi in the example - that was just a typo. In my larger test it is the pattern you suggest - foo and foo-stubs with the latter being .pyi only.

iatkinson avatar Oct 06 '25 02:10 iatkinson

avoid pulling all dependencies of the full package

That's not needed by the way, you could install just the package without its dependencies.

Fair. I might be able to make this work too

iatkinson avatar Oct 06 '25 02:10 iatkinson

Thanks for the report @iatkinson. I guess we could fake the implementation when it isn't found, so that overloads get attached to it, and you'd use relevant options in mkdocstrings to only show the overloads and not the (fake) implementation signature 🤔

That could work, maybe just taking the first overload and duplicating as the implementation signature if it isn't found would be enough?

iatkinson avatar Oct 06 '25 03:10 iatkinson