pdoc3 / pdoc

:snake: :arrow_right: :scroll: Auto-generate API documentation for Python projects
https://pdoc3.github.io/pdoc/
GNU Affero General Public License v3.0
1.11k stars 143 forks source link

PEP224 style docstring not honoured for global variable of type Callable #418

Open edmorley opened 1 year ago

edmorley commented 1 year ago

Summary

If a PEP224 style docstring is used for a global variable of type Callable, that is assigned a function re-exported from another package, the custom docstring is not used, and instead the docstring of the original function is used instead.

I found one way to work around this, which is to overwrite the original function's docstring using get_logger.__doc__ = "Custom docstring", however it seems to me that this perhaps shouldn't be necessary, and that the below might be a bug?

Steps to Reproduce

  1. mkdir -p testcase/mymodule && cd testcase
  2. echo -e 'from typing import Callable\nimport structlog\n\n__all__ = ["get_logger"]\n\nget_logger: Callable[..., structlog.stdlib.BoundLogger] = structlog.stdlib.get_logger\n"""Custom docstring"""' > mymodule/__init__.py
  3. pip install structlog pdoc3
  4. pdoc3 mymodule

This file written above, expanded here to make it easier to read:

from typing import Callable
import structlog

__all__ = ["get_logger"]

get_logger: Callable[..., structlog.stdlib.BoundLogger] = structlog.stdlib.get_logger
"""Custom docstring"""

Expected Behavior

$ pdoc3 mymodule
Module mymodule
===============

Functions
---------

`get_logger(*args: Any, **initial_values: Any) ‑> structlog.stdlib.BoundLogger`
:   Custom docstring

Actual Behavior

$ pdoc3 mymodule
Module mymodule
===============

Functions
---------

`get_logger(*args: Any, **initial_values: Any) ‑> structlog.stdlib.BoundLogger`
:   Only calls `structlog.get_logger`, but has the correct type hints.

    .. warning::

       Does **not** check whether -- or ensure that -- you've configured
       *structlog* for standard library :mod:`logging`!

       See :doc:`standard-library` for details.

    .. versionadded:: 20.2.0

Additional info