Skip to content

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

Open
@edmorley

Description

@edmorley

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions