Skip to content

Documentation not showing because import_hook #359

@Danguilhen

Description

@Danguilhen

Things to check first

  • I have searched the existing issues and didn't find my bug already reported there

  • I have checked that my bug is still present in the latest release

Typeguard version

4.0.0

Python version

3.11.3

What happened?

First, thank you for this amazing package !

This issue is not new (on typeguard 3.0.2 the issue is also there).

If you try the setup I explained just below, the docstring displayed is :

Help on function foo in module src.code:

But without using the install_import_hook, the docstring displays as it should be :

Help on function foo in module src.code:

foo(bar: int = 42)
This docstring won't show up:(

Args:
    bar: The answer to life universe and everything.

The import hook shouldn't make the docstring disappear, the consequence is that the documentation is almost empty after building it with tools like Sphinx 😢

Thank you in advance for considering my issue.

How can we reproduce the bug?

Reproducing the issue is very easy :

Reproduce this file structure :

src
---init.py
---code.py
notebook.ipynb

In the code.py :

def foo(bar: int = 42):
    """This docstring won't show up:(

    Args:
        bar: The answer to life universe and everything.
    """
    print(bar)

In the init.py :

from typeguard import install_import_hook

install_import_hook(__name__)

Finally in a cell of the notebook try:

from src.code import foo

print(help(foo))

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions