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

No way to override "alias of" text, generated by autodoc #4422

Closed
skirpichev opened this issue Jan 12, 2018 · 13 comments
Closed

No way to override "alias of" text, generated by autodoc #4422

skirpichev opened this issue Jan 12, 2018 · 13 comments
Labels
Milestone

Comments

@skirpichev
Copy link
Contributor

Autodoc has problems with resolving references in such text, if the referenced class belongs to the different module, see #2437.

Before #4176 it was possible to workaround this with the currentmodule directive, e.g. here, where this was done to resolve reference to ANP class from polyclasses. Unfortunately, this was broken in latest two releases.

Another option to workaround #2437 would be using comments to document problematic attribute, e.g.:

#: docstring with proper references goes here.
some_attr = SomeClass

Unfortunately, this doesn't work: text "alias of SomeClass" - added after hand-made docstring.

@tk0miya tk0miya added this to the 1.8 milestone Jan 20, 2018
@tk0miya
Copy link
Member

tk0miya commented Jan 20, 2018

+1; it's enough reasonable!

@skirpichev
Copy link
Contributor Author

@tk0miya, not sure if this is still relevant now, after #2437 is fixed.

Ability to override autogenerated text is important only if it's broken, but that shouldn't be the case anymore.

@tk0miya
Copy link
Member

tk0miya commented Jan 20, 2018

I don't think this is workaround for #2437. This is enough useful for documentation.

@tk0miya
Copy link
Member

tk0miya commented Jul 22, 2018

I check this issue again now. And finally I feel this is not needed. #2437 works well to me.
So I'm closing this now.

@tk0miya tk0miya closed this as completed Jul 22, 2018
@LourensVeen
Copy link

I would like to request reopening this issue.

I have a type alias like this:

CopyCallback = Callable[[int, int], None]

which describes the type of a callback function that a user can pass to my copy function. Autodoc currently documents this as:

cerulean.CopyCallback
    alias of typing.Callable

This is not very helpful, first because the arguments to the Callable generic are missing, and second because it doesn't explain what the arguments mean. So I'd like to add a docstring below the definition (and I have), but Autodoc ignores it.

I've added an explanation to the copy function documentation instead, but it would be really nice if the alias could also be documented.

@tk0miya
Copy link
Member

tk0miya commented Nov 23, 2018

Good point! I agree it is useful.
Reopened.

@tk0miya tk0miya reopened this Nov 23, 2018
@tk0miya tk0miya modified the milestones: 1.8.0, 2.0.0 Nov 23, 2018
@tk0miya tk0miya modified the milestones: 2.0.0, 2.1.0 Feb 15, 2019
@tk0miya tk0miya modified the milestones: 2.1.0, 2.2.0 Jun 2, 2019
@tk0miya tk0miya modified the milestones: 2.2.0, 2.3.0 Aug 18, 2019
@pauleikis
Copy link

Another situation I run into where I had to do code changes to force sphinx generate the docstring.
When implementing strategy pattern.

class StrategyA:
    def algorithm(self):
        pass

class StrategyB:
    def algorithm(self):
        pass

class Context:
    strategy = StrategyA
    """
    there is no way to make this docstring appear. It just says 'alias to StrategyA' 
    even though it is  meant to be configurable and only a default here
    """

    def do_something(self):
        self.strategy(self).algorithm()

I did not find a reasonable way to workaround this except doing a code change and setting the default in the __init__ which is not exactly the same.

@tk0miya tk0miya modified the milestones: 2.3.0, 2.4.0 Dec 8, 2019
@tk0miya tk0miya modified the milestones: 2.4.0, 3.0.0 Feb 7, 2020
@tk0miya tk0miya modified the milestones: 3.0.0, 3.1.0 Mar 14, 2020
@jackalcooper
Copy link

Is there any progress on this issue?

tk0miya added a commit to tk0miya/sphinx that referenced this issue May 30, 2020
@tk0miya
Copy link
Member

tk0miya commented May 30, 2020

I just post #7749 to support GenericAlias like CopyCallback.

On the other hand, about @pauleikis's case, latest Sphinx works fine for the example pasted here. So I need to more information to reproduce the trouble. Please file an issue if you still have a problem.

tk0miya added a commit to tk0miya/sphinx that referenced this issue May 30, 2020
tk0miya added a commit to tk0miya/sphinx that referenced this issue May 30, 2020
tk0miya added a commit that referenced this issue May 31, 2020
@tk0miya
Copy link
Member

tk0miya commented May 31, 2020

Now I fixed the behvior for GenericAlias.
Example:

CopyCallback = Callable[[int, int], None]

And I don't change other behaviors. Please file an issue if you still have a problem around "alias of" text.

@Abrosimov-a-a
Copy link

Issue reopen request.

An example of unexpected behavior:

from typing import Union, Type


class MyClass:
    """Class ``MyClass`` docstring."""

    #: This comment is not displayed.
    int_attr = int
    #: This comment is not displayed.
    typed_attr: Union[Type[int], Type[str]] = int
  • Sphinx v3.2.1, v3.5.4
  • Python v3.7

@tk0miya
Copy link
Member

tk0miya commented May 2, 2021

@Abrosimov-a-a Could you file a new issue, please?

@Abrosimov-a-a
Copy link

@tk0miya Created #9218

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 10, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

6 participants