Skip to content

Linking to implicit namespace package with :py:mod: not working #9608

@estan

Description

@estan

Describe the bug

The documentation for :py:mod: says that it can also be used to link to packages. This seems to work for regular packages, but not implicit namespace packages.

How to Reproduce

mkdir -p testcase/foo
cd testcase
touch foo/bar.py
python3 -m venv venv
source venv/bin/activate
pip install sphinx
mkdir source
echo 'import os; import sys; sys.path.insert(0, os.path.abspath("..")); extensions = ["sphinx.ext.autodoc"]' > source/conf.py
sphinx-apidoc -f --implicit-namespaces -o source foo
echo ':py:mod:`foo`' > source/index.rst
sphinx-build source build
xdg-open build/index.html

Notice how "foo" in the output is not a hyperlink.

On the other hand, if we turn foo into a regular package and re-run sphinx-apidoc / sphinx-build:

touch foo/__init__.py
sphinx-apidoc -f -o source foo
sphinx-build source build
xdg-open build/index.html

Then "foo" is now a hyperlink.

Expected behavior

I expect "foo" in the output to be a link to foo.html#foo-namespace.

Your project

See steps above

Screenshots

No response

OS

Ubuntu 20.04.3 LTS

Python version

3.8.10

Sphinx version

4.1.2

Sphinx extensions

sphinx.ext.autodoc

Extra tools

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions