How to create aliases to functions/classes/etc. ?

27 views
Skip to first unread message

Yury Gorishniy

unread,
Jun 23, 2020, 4:53:13 PM6/23/20
to sphinx-users
Hi! I'm using sphinx==3.1.1. I have a package `foo` with a subpackage `bar`. I also have a class :class:`foo.bar.Bar`.
Is there any way to create references to `Bar` as :class:`Bar`, not as :class:`foo.bar.Bar` ?

Matthias Geier

unread,
Jun 24, 2020, 4:27:15 AM6/24/20
to sphinx...@googlegroups.com
> Hi! I'm using sphinx==3.1.1. I have a package `foo` with a subpackage `bar`. I also have a class :class:`foo.bar.Bar`.
> Is there any way to create references to `Bar` as :class:`Bar`, not as :class:`foo.bar.Bar` ?

If you want to write "foo.bar.Bar" but only display "Bar":

:class:`~foo.bar.Bar` (note the "tilde" character)

If you want to write "Bar":

.. currentmodule:: foo.bar

:class:`Bar`

Does that help?

cheers,
Matthias

Yury Gorishniy

unread,
Jun 24, 2020, 6:55:28 AM6/24/20
to sphinx-users
> Does that help?
To some extent, thank you. I think my explanation was not good enough. What I mean is writing :class:`Bar` from anywhere without ..currentmodule::. It implies explicit creating of such "alias" in a docstring. Like this:
```
# foo/bar.py
class Bar:
    """
    ...

    Alias:
        Bar
    """
```

Is there such functionality?

mohamed Alisaleh

unread,
Jun 26, 2020, 7:45:56 PM6/26/20
to sphinx-users
مرحبا كيف يمكنني بناء موقعي الذي المشاركة مع مجموعة قوقل

Daniel Scott

unread,
Jun 28, 2020, 2:37:35 AM6/28/20
to sphinx-users
On Tuesday, June 23, 2020 at 1:53:13 PM UTC-7, Yury Gorishniy wrote:
> Hi! I'm using sphinx==3.1.1. I have a package `foo` with a subpackage `bar`. I also have a class :class:`foo.bar.Bar`.
> Is there any way to create references to `Bar` as :class:`Bar`, not as :class:`foo.bar.Bar` ?

9

Daniel Scott

unread,
Jun 28, 2020, 2:38:05 AM6/28/20
to sphinx-users
On Tuesday, June 23, 2020 at 1:53:13 PM UTC-7, Yury Gorishniy wrote:

Daniel Scott

unread,
Jun 28, 2020, 2:39:48 AM6/28/20
to sphinx-users
On Tuesday, June 23, 2020 at 1:53:13 PM UTC-7, Yury Gorishniy wrote:
> Hi! I'm using sphinx==3.1.1. I have a package `foo` with a subpackage `bar`. I also have a class :class:`foo.bar.Bar`.
> Is there any way to create references to `Bar` as :class:`Bar`, not as :class:`foo.bar.Bar` ?

Like to use this message to post sphinx package.

Daniel Scott

unread,
Nov 25, 2020, 10:39:07 PM11/25/20
to sphinx...@googlegroups.com
--
You received this message because you are subscribed to the Google Groups "sphinx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sphinx-users...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sphinx-users/c8904b34-02b2-4160-b905-a2f6c643dc75o%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages