Skip to content

bug: filters: [] not usable when group_by_category is set to false #324

@T0nyX1ang

Description

@T0nyX1ang

To Reproduce

Here is a simple module with a public and a protected function.

def test():
    """test."""
    pass

def _test():
    """_test."""
    pass

Other options can be set to default values as follows.

plugins:
  - mkdocstrings:
      default_handler: python
      handlers:
        python:
          options:
            group_by_category: false
            filters: []

Then, the _test() method is not appeared in the generated document.

Full traceback

Full traceback
DEBUG   -  mkdocstrings_handlers: python\templates\material\function.html.jinja: Rendering mod.test.test
DEBUG   -  mkdocstrings_handlers: python\templates\material\signature.html.jinja: Rendering signature
DEBUG   -  mkdocstrings_handlers: python\templates\material\docstring.html.jinja: Rendering docstring

# the following lines won't appear if `group_by_category` is set to `false`
DEBUG   -  mkdocstrings_handlers: python\templates\material\function.html.jinja: Rendering mod.test._test
DEBUG   -  mkdocstrings_handlers: python\templates\material\signature.html.jinja: Rendering signature
DEBUG   -  mkdocstrings_handlers: python\templates\material\docstring.html.jinja: Rendering docstring

Expected behavior

Environment information

  • System: Windows 10
  • Python: cpython 3.10.11
  • Environment variables:
  • Installed packages:
    • mkdocstrings-python v2.0.0

Additional context

I have tried to pinpoint the issue in children.html.jinja, and find the following lines:

{% if config.group_by_category %}
... irrelevant codes here ...
    {% else %}

      {% for child in obj.all_members
          |filter_objects(
            filters=config.filters,
            members_list=members_list,
            inherited_members=config.inherited_members,
            keep_no_docstrings=config.show_if_no_docstring,
            )
          |order_members(config.members_order, members_list)
        %}

        {% if not (obj.is_class and child.name == "__init__" and config.merge_init_into_class) %}

          {% if config.filters == "public" or members_list is not none or child.is_public %}
          ... rendering codes here ...
          {% endif %}

        {% endif %}

      {% endfor %}

    {% endif %}

I validate the filtering part, and the results are correct, so the problem may be inside the rendering part. Comparing with the similar codes in the if-branch, there is a significant difference in the code:

{% if config.filters == "public" or members_list is not none or (not child.is_imported or child.is_public) %}

After adding these lines, the problem will be resolved on my device.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions