Skip to content

show_category_heading: true and group_by_category: true does not work #14

Closed

Description

@pedrolabonia

Describe the bug
Using show_category_heading: true and group_by_category: true does not work.

To Reproduce
Enable these settings

Expected behavior
Expected to have TOC separate them

Fix

The bug seems to happen here

{% if config.show_category_heading and obj.attributes.values()|any %}

Removing any() results in the expected behavior.

Since we're calling .values(), if there's no values it already returns False.

Activity

  1. pedrolabonia commented on Apr 15, 2022

    @pedrolabonia
    Author

    Proposed fix: pedrolabonia@0772ccc

  2. pawamoy commented on Apr 16, 2022

    @pawamoy
    Member

    The point of the any filter is actually to filter out objects that have no docstring or an empty docstring. And I realize it's actually insufficient to do it like that.

    Let say show_if_no_docstring is false, and there's one function with no docstring in obj.functions.values(). Without any we would render the category header for nothing (the category is empty).

    Now if show_if_no_docstring is true, we shouldn't filter out with any, and just check if there are objects.

    I think we need a more powerful function on the handler's side, to do this filtering for us based on the show_if_no_docstring option. This way we won't have to resort to the any filter anymore.

  3. pedrolabonia commented on Apr 16, 2022

    @pedrolabonia
    Author

    Hmm.. I get it. So that function would be in the handler.py in this repo? I confess I'm not used to working with jinja and markdown that much so I'm a little green yet and trying to figure out the data flow between mkdocstrings-python and mkdocstrings. If you have any direction I can give it a go.

  4. added a commit that references this issue on Apr 16, 2022
  5. pawamoy commented on Apr 16, 2022

    @pawamoy
    Member

    Well I wanted to see how it could be done and I ended up implementing the change 😅
    I hope you don't mind! Let me know what you think of #16.

  6. pawamoy commented on Apr 16, 2022

    @pawamoy
    Member

    Also, can you confirm that the original issue was that in some cases the category headings were not rendered? It isn't clear in the description.

  7. pedrolabonia commented on Apr 16, 2022

    @pedrolabonia
    Author

    In my case, I could never get them to render the category headings at all, and could never group the children by category.

    My object tree consisted of basically methods, properties and attributes with a parent class.

    No nesting or things like that.

  8. added a commit that references this issue on Apr 18, 2022
  9. pawamoy commented on Apr 18, 2022

    @pawamoy
    Member

    OK I've merged the PR. We'll need to wait for a new release of mkdocstrings before releasing one for the handler. That should'nt take too long.

  10. added a commit that references this issue on Feb 24, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions