PEP224 style docstring not honoured for global variable of type Callable
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.2k
- Forks
- 146
- PR merge metrics
- No merged PRs in 30d
Description
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
mkdir -p testcase/mymodule && cd testcaseecho -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__.pypip install structlog pdoc3pdoc3 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
- pdoc version: 0.10.0
- Python version: 3.11.1
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the issue with testcase/mymodule/init.py using the shown Callable assignment and PEP224-style docstring, then run pdoc3 mymodule. Trace the documentation generation path for this module-level callable and compare the rendered output with the expected Markdown. Done means the custom docstring is shown instead of the re-exported function's original docstring.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- documentation
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100