Skip to content

Commit 053bf20

Browse files
committed
feat: Allow passing literal docstring styles everywhere in the API, not just Parser enumeration values
1 parent 9929f47 commit 053bf20

File tree

4 files changed

+19
-15
lines changed

4 files changed

+19
-15
lines changed

src/_griffe/agents/inspector.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
from collections.abc import Sequence
2323
from pathlib import Path
2424

25+
from _griffe.docstrings.parsers import DocstringStyle
2526
from _griffe.enumerations import Parser
2627
from _griffe.expressions import Expr
2728

@@ -36,7 +37,7 @@ def inspect(
3637
import_paths: Sequence[str | Path] | None = None,
3738
extensions: Extensions | None = None,
3839
parent: Module | None = None,
39-
docstring_parser: Parser | None = None,
40+
docstring_parser: DocstringStyle | Parser | None = None,
4041
docstring_options: dict[str, Any] | None = None,
4142
lines_collection: LinesCollection | None = None,
4243
modules_collection: ModulesCollection | None = None,
@@ -103,7 +104,7 @@ def __init__(
103104
filepath: Path | None,
104105
extensions: Extensions,
105106
parent: Module | None = None,
106-
docstring_parser: Parser | None = None,
107+
docstring_parser: DocstringStyle | Parser | None = None,
107108
docstring_options: dict[str, Any] | None = None,
108109
lines_collection: LinesCollection | None = None,
109110
modules_collection: ModulesCollection | None = None,
@@ -137,7 +138,7 @@ def __init__(
137138
self.current: Module | Class = None # type: ignore[assignment]
138139
"""The current object being inspected."""
139140

140-
self.docstring_parser: Parser | None = docstring_parser
141+
self.docstring_parser: DocstringStyle | Parser | None = docstring_parser
141142
"""The docstring parser to use."""
142143

143144
self.docstring_options: dict[str, Any] = docstring_options or {}

src/_griffe/agents/visitor.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
if TYPE_CHECKING:
3535
from pathlib import Path
3636

37+
from _griffe.docstrings.parsers import DocstringStyle
3738
from _griffe.enumerations import Parser
3839

3940

@@ -68,7 +69,7 @@ def visit(
6869
*,
6970
extensions: Extensions | None = None,
7071
parent: Module | None = None,
71-
docstring_parser: Parser | None = None,
72+
docstring_parser: DocstringStyle | Parser | None = None,
7273
docstring_options: dict[str, Any] | None = None,
7374
lines_collection: LinesCollection | None = None,
7475
modules_collection: ModulesCollection | None = None,
@@ -125,7 +126,7 @@ def __init__(
125126
code: str,
126127
extensions: Extensions,
127128
parent: Module | None = None,
128-
docstring_parser: Parser | None = None,
129+
docstring_parser: DocstringStyle | Parser | None = None,
129130
docstring_options: dict[str, Any] | None = None,
130131
lines_collection: LinesCollection | None = None,
131132
modules_collection: ModulesCollection | None = None,
@@ -163,7 +164,7 @@ def __init__(
163164
self.current: Module | Class = None # type: ignore[assignment]
164165
"""The current object being visited."""
165166

166-
self.docstring_parser: Parser | None = docstring_parser
167+
self.docstring_parser: DocstringStyle | Parser | None = docstring_parser
167168
"""The docstring parser to use."""
168169

169170
self.docstring_options: dict[str, Any] = docstring_options or {}

src/_griffe/loader.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
if TYPE_CHECKING:
3131
from collections.abc import Sequence
3232

33+
from _griffe.docstrings.parsers import DocstringStyle
3334
from _griffe.enumerations import Parser
3435

3536

@@ -47,7 +48,7 @@ def __init__(
4748
*,
4849
extensions: Extensions | None = None,
4950
search_paths: Sequence[str | Path] | None = None,
50-
docstring_parser: Parser | None = None,
51+
docstring_parser: DocstringStyle | Parser | None = None,
5152
docstring_options: dict[str, Any] | None = None,
5253
lines_collection: LinesCollection | None = None,
5354
modules_collection: ModulesCollection | None = None,
@@ -69,7 +70,7 @@ def __init__(
6970
"""
7071
self.extensions: Extensions = extensions or load_extensions()
7172
"""Loaded Griffe extensions."""
72-
self.docstring_parser: Parser | None = docstring_parser
73+
self.docstring_parser: DocstringStyle | Parser | None = docstring_parser
7374
"""Selected docstring parser."""
7475
self.docstring_options: dict[str, Any] = docstring_options or {}
7576
"""Configured parsing options."""
@@ -714,7 +715,7 @@ def load(
714715
try_relative_path: bool = True,
715716
extensions: Extensions | None = None,
716717
search_paths: Sequence[str | Path] | None = None,
717-
docstring_parser: Parser | None = None,
718+
docstring_parser: DocstringStyle | Parser | None = None,
718719
docstring_options: dict[str, Any] | None = None,
719720
lines_collection: LinesCollection | None = None,
720721
modules_collection: ModulesCollection | None = None,
@@ -820,7 +821,7 @@ def load_git(
820821
submodules: bool = True,
821822
extensions: Extensions | None = None,
822823
search_paths: Sequence[str | Path] | None = None,
823-
docstring_parser: Parser | None = None,
824+
docstring_parser: DocstringStyle | Parser | None = None,
824825
docstring_options: dict[str, Any] | None = None,
825826
lines_collection: LinesCollection | None = None,
826827
modules_collection: ModulesCollection | None = None,
@@ -904,7 +905,7 @@ def load_pypi(
904905
submodules: bool = True, # noqa: ARG001
905906
extensions: Extensions | None = None, # noqa: ARG001
906907
search_paths: Sequence[str | Path] | None = None, # noqa: ARG001
907-
docstring_parser: Parser | None = None, # noqa: ARG001
908+
docstring_parser: DocstringStyle | Parser | None = None, # noqa: ARG001
908909
docstring_options: dict[str, Any] | None = None, # noqa: ARG001
909910
lines_collection: LinesCollection | None = None, # noqa: ARG001
910911
modules_collection: ModulesCollection | None = None, # noqa: ARG001

src/_griffe/tests.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
from collections.abc import Iterator, Mapping, Sequence
2424

2525
from _griffe.collections import ModulesCollection
26+
from _griffe.docstrings.parsers import DocstringStyle
2627
from _griffe.enumerations import Parser
2728
from _griffe.extensions.base import Extensions
2829

@@ -124,7 +125,7 @@ def temporary_visited_package(
124125
init: bool = True,
125126
inits: bool = True,
126127
extensions: Extensions | None = None,
127-
docstring_parser: Parser | None = None,
128+
docstring_parser: DocstringStyle | Parser | None = None,
128129
docstring_options: dict[str, Any] | None = None,
129130
lines_collection: LinesCollection | None = None,
130131
modules_collection: ModulesCollection | None = None,
@@ -189,7 +190,7 @@ def temporary_inspected_package(
189190
init: bool = True,
190191
inits: bool = True,
191192
extensions: Extensions | None = None,
192-
docstring_parser: Parser | None = None,
193+
docstring_parser: DocstringStyle | Parser | None = None,
193194
docstring_options: dict[str, Any] | None = None,
194195
lines_collection: LinesCollection | None = None,
195196
modules_collection: ModulesCollection | None = None,
@@ -259,7 +260,7 @@ def temporary_visited_module(
259260
module_name: str = "module",
260261
extensions: Extensions | None = None,
261262
parent: Module | None = None,
262-
docstring_parser: Parser | None = None,
263+
docstring_parser: DocstringStyle | Parser | None = None,
263264
docstring_options: dict[str, Any] | None = None,
264265
lines_collection: LinesCollection | None = None,
265266
modules_collection: ModulesCollection | None = None,
@@ -306,7 +307,7 @@ def temporary_inspected_module(
306307
import_paths: list[Path] | None = None,
307308
extensions: Extensions | None = None,
308309
parent: Module | None = None,
309-
docstring_parser: Parser | None = None,
310+
docstring_parser: DocstringStyle | Parser | None = None,
310311
docstring_options: dict[str, Any] | None = None,
311312
lines_collection: LinesCollection | None = None,
312313
modules_collection: ModulesCollection | None = None,

0 commit comments

Comments
 (0)