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

Make default_role aware of aliases. #9453

Open
randolf-scholz opened this issue Jul 15, 2021 · 0 comments
Open

Make default_role aware of aliases. #9453

randolf-scholz opened this issue Jul 15, 2021 · 0 comments
Labels
type:enhancement enhance or introduce a new feature

Comments

@randolf-scholz
Copy link

randolf-scholz commented Jul 15, 2021

Is your feature request related to a problem? Please describe.
When we want to make use of the fantastic intersphinx extension, we unfortunately often end up having to write very verbose docstrings such as

Takes the input :class:`~module.submodule.subsubmodule.SomeClass` and ...

This has 3 major disadvantages:

  1. It is very annoying to type.
  2. It is annoying to maintain. If one moves a class definition to some other submodule, all occurrences of :class:`~module.submodule.subsubmodule.SomeClass ` need to be refactored.
  3. It greatly reduces legibility of help() strings when executed from a terminal or in a Jupyter Notebook.

Describe the solution you'd like
My proposal is to add some additional logic to the default_role option. Currently, if we use something like default_role="py:obj", all it seems to do is replace occurrences of `object` with :py:obj:`object` .

Instead, I would suggest that first, a check should be performed to see if `object` is contained in either autodoc_type_aliases (or napoleon_type_aliases if napoleon is enabled).

If the object is found there, then `object` should be replaced with the found alias instead of the "default" default_role. This would elegantly solve all 3 problems outlined above.

Describe alternatives you've considered
None so far. The additional default_role logic should probably come with a boolean switch to turn it off and on.

Additional context

So for instance, if we had

default_role = "py:obj"
napoleon_type_aliases = {
    "Tensor" : ":py:class:`~torch.Tensor`",
}

Then the docstring

"Takes as input an `array_like` and outputs a `Tensor`."

Should be translated to

"Takes as input an :py:obj:`array_like` and outputs a :py:class:`~torch.Tensor`."

Related:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:enhancement enhance or introduce a new feature
Projects
None yet
Development

No branches or pull requests

2 participants