pdoc3 / pdoc3/pdoc

PEP224 style docstring not honoured for global variable of type Callable

Open
#418 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
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
  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
  • pdoc version: 0.10.0
  • Python version: 3.11.1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.