Skip to content

Commit

Permalink
fix: Allow passing null as docstring style
Browse files Browse the repository at this point in the history
Issue #2: #2
  • Loading branch information
pawamoy committed Feb 8, 2022
1 parent a65f6b1 commit f526816
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/mkdocstrings_handlers/python/collector.py
Expand Up @@ -52,14 +52,15 @@ def collect(self, identifier: str, config: dict) -> CollectorItem: # noqa: WPS2
final_config = ChainMap(config, self.default_config)
parser_name = final_config["docstring_style"]
parser_options = final_config["docstring_options"]
parser = parser_name and Parser(parser_name)

just_loaded = False
module_name = identifier.split(".", 1)[0]
if module_name not in self._modules_collection:
just_loaded = True
loader = GriffeLoader(
extensions=load_extensions(final_config.get("extensions", [])),
docstring_parser=Parser(parser_name),
docstring_parser=parser,
docstring_options=parser_options,
modules_collection=self._modules_collection,
lines_collection=self._lines_collection,
Expand All @@ -79,7 +80,7 @@ def collect(self, identifier: str, config: dict) -> CollectorItem: # noqa: WPS2
raise CollectionError(f"{identifier} could not be found") from error

if not just_loaded and doc_object.docstring is not None:
doc_object.docstring.parser = parser_name and Parser(parser_name)
doc_object.docstring.parser = parser
doc_object.docstring.parser_options = parser_options

return doc_object
6 changes: 6 additions & 0 deletions tests/test_collector.py
Expand Up @@ -23,3 +23,9 @@ def test_collect_module():
"""Assert existing module can be collected."""
collector = PythonCollector()
assert collector.collect("mkdocstrings", {})


def test_collect_with_null_parser():
"""Assert we can pass `None` as parser when collecting."""
collector = PythonCollector()
assert collector.collect("mkdocstrings", {"docstring_style": None})

0 comments on commit f526816

Please sign in to comment.