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

Automodule interprets the definition of descriptor types as attributes #1526

Closed
shimizukawa opened this issue Jan 3, 2015 · 2 comments
Closed

Comments

@shimizukawa
Copy link
Member

  1. Create a descriptor type in a module

  2. create a document with

     .. automodule:: <module>
        :members:
        :show-inheritance:
    

Expected: documents the class as a class, documents its members and shows its inheritance
Observed: documents the class as an attribute, just shows its docstring

Problem source

AttributeDocumenter has a higher priority than ClassDocumenter and if the member being checked (in can_document_member) is a descriptor all other checks are ignored

Partial solution

put the isdatatesc check under not isinstance(parent, ModuleDocumenter) somehow: descriptors don't work at the module-level (save through shenanigans of explicitly creating a ModuleType subclass and shoving it into sys.modules by hand)

Issue remaining

defining a descriptor type as an inner class will still be incorrectly documented as an attribute

Alternative solution

Add not isinstance(member, class_types) in the decision tree for isdatadesc


@shimizukawa
Copy link
Member Author

From Kevin Norris on 2014-09-11 03:03:36+00:00

I don't see this under 1.2.3. I believe https://bitbucket.org/birkenfeld/sphinx/pull-request/107 may have fixed it.

However, I do see a slightly more complex bug. If the descriptor type has a metaclass (like, say, abc.ABCMeta), the issue reappears. This is apparently because the pull request compares the __name__ of the type() of the thing being documented (i.e. member) to (among other things) "type". Since metaclasses can have arbitrary names, it is not at all obvious how this approach can be generalized. I'd recommend replacing the string compare with a isinstance(member, type) check or something similar.

@shimizukawa
Copy link
Member Author

Original issue was fixed at sphinx-1.2.3 release.
And now additionally reported issue also fixed by #1843.

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

No branches or pull requests

1 participant