diff --git a/pdoc/render_helpers.py b/pdoc/render_helpers.py index b3672ca5..1497defc 100644 --- a/pdoc/render_helpers.py +++ b/pdoc/render_helpers.py @@ -212,10 +212,13 @@ def possible_sources( yield identifier, "" return - if len(set(s.partition(".")[0] for s in all_modules)) == 1: + # handle relative identifiers + if identifier.startswith("."): pkgname = next(iter(all_modules)).partition(".")[0] - if not identifier.startswith(pkgname): - identifier = f"{pkgname}.{identifier}" + # check that all modules reside within the same top-level module + if all(s.startswith(pkgname + ".") or s == pkgname for s in all_modules): + if not identifier.startswith(pkgname): + identifier = f"{pkgname}{identifier}" modulename = identifier qualname = None @@ -342,7 +345,7 @@ def linkify_repl(m: re.Match): r""" # Part 1: foo.bar or foo.bar() (without backticks) (? -

This class is defined in .child_c and inherits from .demopackage.B

+

This class is defined in .child_c and inherits from demopackage.B

diff --git a/test/testdata/single_module_links.html b/test/testdata/single_module_links.html index a1b0e746..15694559 100644 --- a/test/testdata/single_module_links.html +++ b/test/testdata/single_module_links.html @@ -62,7 +62,7 @@

6 ''' 7 Test that submodules are linked to when documenting a single module. 8 - 9 Do `helpers.something` with a `types.BigThing` + 9 Do `.helpers.something` with a `.types.BigThing` 10 ''' 11 something() 12 BigThing() @@ -85,7 +85,7 @@

7 ''' 8 Test that submodules are linked to when documenting a single module. 9 -10 Do `helpers.something` with a `types.BigThing` +10 Do `.helpers.something` with a `.types.BigThing` 11 ''' 12 something() 13 BigThing() @@ -94,7 +94,7 @@

Test that submodules are linked to when documenting a single module.

-

Do helpers.something with a types.BigThing

+

Do .helpers.something with a .types.BigThing

diff --git a/test/testdata/single_module_links/__init__.py b/test/testdata/single_module_links/__init__.py index a8c14301..57b24933 100644 --- a/test/testdata/single_module_links/__init__.py +++ b/test/testdata/single_module_links/__init__.py @@ -6,7 +6,7 @@ def abc(): ''' Test that submodules are linked to when documenting a single module. - Do `helpers.something` with a `types.BigThing` + Do `.helpers.something` with a `.types.BigThing` ''' something() BigThing()