Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add module name rewrite configuration option #474

Merged
merged 6 commits into from
Aug 29, 2024

Conversation

hoodmane
Copy link
Collaborator

@hoodmane hoodmane commented Aug 28, 2024

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.
gaborbernat
gaborbernat previously approved these changes Aug 28, 2024
Copy link
Member

@gaborbernat gaborbernat left a comment

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
Copy link
Member

@gaborbernat gaborbernat left a comment

Choose a reason for hiding this comment

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

@gaborbernat gaborbernat merged commit 6d91418 into tox-dev:main Aug 29, 2024
7 of 8 checks passed
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