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

duplicated attributes table when used with 'summary : true' #18

Open
osamimi opened this issue Jan 28, 2025 · 5 comments
Open

duplicated attributes table when used with 'summary : true' #18

osamimi opened this issue Jan 28, 2025 · 5 comments

Comments

@osamimi
Copy link

osamimi commented Jan 28, 2025

I use the 'summary: true' option of mkdocstrings-python. It is most useful to generate a summary table of all the functions in a module. It also generates a summary table of a class's attributes and methods, but so does Griffe-fields, leading to two tables.
I want the griffe-fields version here because it shows the defaults, but if set 'summary: false' I lose the summary tables in other places.

Any ideas on how to avoid this?

Image

@tlambert03
Copy link
Member

Thanks for the issue @osamimi

This is something I’ve noticed and wanted to fix too. I’m actually not sure it relates to the summary table though, but rather how we “merge” the parameters and attributes (which are sometimes sort of the same thing in a dataclass). But to know that here, I’d need to see the source code (specifically: the docstring) of your example here . Could you paste that here?

@osamimi
Copy link
Author

osamimi commented Jan 28, 2025

Hi @tlambert03
I actually just realized that the summary table can be turned off just for attributes :

https://mkdocstrings.github.io/python/usage/configuration/members/#summary

summary:
attributes: false
functions: true
modules: true
classes: true

So now this pydantic model

class CMAES_PYCMA(_FrozenDataClass, frozen=True):
    max_iter: int
    """Maximum number of iterations"""

    sigma_mult: float = 1.0
    pop_size_mult: int = 2
    n_workers: int = 1
    batch_fitness: bool = True
    disp_every: int = 500
    tol: float = 0.0
    _multi_obj: bool = PrivateAttr(default=False)

produces the following :

Image

Here is my mkdocs.yml:

  - mkdocstrings:
      handlers:
        python:
          paths: src/filtpy
          import:
            - url: https://docs.python.org/3/objects.inv
              domains: [py, std]
          options:
            extensions:
              - griffe_inherited_docstrings
              - griffe_fieldz: {include_inherited: true}
            members_order: "source"
            show_source : true
            show_bases : true
            parameter_headings: false
            summary:
                attributes: false
                functions: true
                modules: true
                classes: true
            show_symbol_type_heading : true
            show_category_heading: false
            docstring_style : "google"
            docstring_section_style : "table"
            show_if_no_docstring : true # FIXME: change to false
            signature_crossrefs : true
            show_signature: true
            show_signature_annotations : true
            show_root_heading: false
            merge_init_into_class: true
            show_root_full_path: true
            show_root_members_full_path: false
            show_object_full_path: false
            show_symbol_type_toc: true
            separate_signature: true
            heading_level: 2
            inherited_members: true
            filters:
             - "!^_"

The only problem is the missing docstring for max_iter for example. I opened another issue for that

@tlambert03
Copy link
Member

I actually just realized that the summary table can be turned off just for attributes

well that's very useful thanks. We still might be able to do better here in terms of merging... but this is a useful thing to know.

missing docstring for max_iter for example. I opened another issue for that

yes, the docstring-below the attribute thing is something that @AdrianSosic happened to also be asking about just yesterday: #17 (comment)

so that makes two of you. will get on it soon

@osamimi
Copy link
Author

osamimi commented Jan 29, 2025

Just saw your reply after filing #19
I am honestly a bit confused about all this now, so hopefully the bug report made sense.
Adding support for the docstring under attribute thing would make it all work for my use case I think.

Thanks for the help!

@tlambert03
Copy link
Member

thank you for the additional detail there. hope to have a look in the next couple days

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants