Skip to content

display names relative to the package's namespace #4065

@Aran-Fey

Description

@Aran-Fey

Note: This post has been massively edited because it was originally based on a misunderstanding on my part. I hope it makes more sense now. Unfortunately I can't seem to edit the title.


Consider a project structured like this:

package/
    __init__.py
    module.py

__init__.py contains:

from .module import Class

module.py contains:

class Class:
    pass

The docs generated by autodoc look like this:

package package

Submodules
package.module module

class package.module.Class

  Bases: object

Module contents

This is very different from what the user is supposed to see. A user would import Class with from package import Class, not with from package.module import Class. The user doesn't need to know in which file Class was defined. From the user's perspective, Class is located in package, and module doesn't even exist. The docs would be a lot more helpful if they looked like this:

package module

Module contents

class Class

The relevant changes I made are the following:

  1. Class is listed directly in package rather than in package.module
  2. module isn't listed as a submodule, because it doesn't contain anything relevant

This accurately displays package's public interface; there is no useless non-information in this documentation. If autodoc could produce output like this, it would be a massive improvement.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions