-
-
Notifications
You must be signed in to change notification settings - Fork 107
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add module name rewrite configuration option
This adds a configuration option that allows the user to rewrite module names if needed. Resolves #473. Note that we also rewrite the names of `_io` and `typing_extensions` internally. One benefit of this hook is that if other similar rewrites are needed, users will be able to immediately add them without having to patch sphinx_autodoc_typehints itself. One disadvantage is that by default, having a function in the config prevents caching. I think this can be handled with the following slightly inelegant hack: ```py class ModuleNameRewriteHook: version: int def __eq__(self, other): return type(self) == type(other) and self.version == other.version def __init__(self): self.version = 2 def __call__(self, module): # logic here # Make sure to bump version if you edit this so that sphinx will rerun. return module typehints_fixup_module_name = ModuleNameRewriteHook ``` See sphinx-doc/sphinx#12300.
- Loading branch information
Showing
6 changed files
with
54 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
from __future__ import annotations | ||
|
||
from wrong_module_path import A, f | ||
|
||
__all__ = ["A", "f"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
from __future__ import annotations | ||
|
||
|
||
class A: | ||
pass | ||
|
||
|
||
def f() -> A: | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.. class:: export_module.A | ||
|
||
.. autofunction:: export_module.f |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters