mkdocstrings / python

A Python handler for mkdocstrings.
https://mkdocstrings.github.io/python
ISC License
189 stars 35 forks source link

bug: Docstring Style Local Override Does Not Work #183

Open triley13 opened 2 months ago

triley13 commented 2 months ago

Description of the bug

Local override docstring_style for global configuration doesn't work.

To Reproduce

Declare in mkdocs.yaml:

plugins:
  - mkdocstrings:
      enabled: true
      default_handler: python
      handlers:
        python:
          options:
            docstring_style: google

-->

Inside file.md

::: path.to.module
    options:
      docstring_style: sphinx

Full traceback

Full traceback ```python N/A ```

Expected behavior

Override the default google style with the sphinx style for that one module.

Environment information

Additional context

I am using path: to load the module and I'm using mkdocs-monorepo-plugin.

pawamoy commented 2 months ago

Thanks for the report @triley13 :slightly_smiling_face:

I suppose you expect all objects within path.to.module to be parsed as Sphinx-style, right? Currently we only re-assign the style to the specific object but not its members.

Ideally we would distinguish that a local option was used, and instead of re-assigning a style, we would use the provided local style to parse docstrings. The issue is that we're not able to differentiate a global option from a local one once we're in the render method of the handler :thinking:

pawamoy commented 2 months ago

We can re-assign the style to the object and all its members, but note that Griffe extensions that modify the cached and parsed version of the docstring will probably stop working (because such extensions would be initially parsing and caching the docstring with the global style, not the local one).

WDYT?

triley13 commented 1 month ago

Hey @pawamoy, sorry I've been on vacation for a bit. Is caching necessary? If it's not, then I would suggest making an implementation that only works without caching. Otherwise, is there a workaround for parsing the docstrings for a single page, and limiting the style change to a particular webpage?