Skip to content

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

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

Closed
pedrolabonia opened this issue Apr 15, 2022 · 7 comments
Closed

Comments

@pedrolabonia
Copy link

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.

@pedrolabonia
Copy link
Author

Proposed fix: pedrolabonia@0772ccc

@pawamoy
Copy link
Member

pawamoy commented Apr 16, 2022

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.

@pedrolabonia
Copy link
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.

pawamoy added a commit that referenced this issue Apr 16, 2022
@pawamoy
Copy link
Member

pawamoy commented Apr 16, 2022

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.

@pawamoy
Copy link
Member

pawamoy commented Apr 16, 2022

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.

@pedrolabonia
Copy link
Author

pedrolabonia commented Apr 16, 2022

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.

pawamoy added a commit that referenced this issue Apr 18, 2022
@pawamoy
Copy link
Member

pawamoy commented Apr 18, 2022

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.

@pawamoy pawamoy closed this as completed Apr 18, 2022
viktorlashchuk added a commit to viktorlashchuk/mkdocstrings-python that referenced this issue Feb 24, 2025
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

Successfully merging a pull request may close this issue.

2 participants