Skip to content

Add module name rewrite configuration option#474

Merged
gaborbernat merged 6 commits into
tox-dev:mainfrom
hoodmane:fixup-module-name-hook
Aug 29, 2024
Merged

Add module name rewrite configuration option#474
gaborbernat merged 6 commits into
tox-dev:mainfrom
hoodmane:fixup-module-name-hook

Conversation

@hoodmane

@hoodmane hoodmane commented Aug 28, 2024

Copy link
Copy Markdown
Collaborator

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:

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.

This adds a configuration option that allows the user to rewrite module names if
needed. Resolves tox-dev#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.
@hoodmane
hoodmane force-pushed the fixup-module-name-hook branch from 8067650 to e74cc58 Compare August 28, 2024 10:11
gaborbernat
gaborbernat previously approved these changes Aug 28, 2024

@gaborbernat gaborbernat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@hoodmane
hoodmane enabled auto-merge (squash) August 29, 2024 08:59

@gaborbernat gaborbernat left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gaborbernat
gaborbernat disabled auto-merge August 29, 2024 16:24
@gaborbernat
gaborbernat merged commit 6d91418 into tox-dev:main Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Intersphinx Mapping link not working with Plotly objects in signature

2 participants