Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
edmorley opened this issue Jan 11, 2023 · 0 comments
Open

Comments

@edmorley
Copy link

edmorley commented Jan 11, 2023

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant