Skip to content

Commit 02892b3

Browse files
committed
docs: Simplify docstring parsing examples
1 parent ce59b7d commit 02892b3

1 file changed

Lines changed: 4 additions & 8 deletions

File tree

docs/parsing_docstrings.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,16 @@
22

33
You can use Griffe to parse arbitrary docstrings.
44
You don't have to load anything through the Griffe loader.
5-
You need to import the [`parse`][griffe.docstrings.parsers.parse] function,
6-
the [`Parser`][griffe.docstrings.parsers.Parser] enumeration,
7-
and the [`Docstring`][griffe.dataclasses.Docstring] class.
8-
Then you can build a `Docstring` instance and call `parse` on it,
5+
You just need to import the [`Docstring`][griffe.dataclasses.Docstring] class.
6+
Then you can build a `Docstring` instance and call its `parse` method,
97
choosing the parsing-style to use:
108

119
```python
1210
from griffe.dataclasses import Docstring
13-
from griffe.docstrings.parsers import Parser, parse
1411

1512
text = "Hello I'm a docstring!"
1613
docstring = Docstring(text, lineno=1)
17-
parsed = parse(docstring, Parser.google)
14+
parsed = docstring.parse("google")
1815
```
1916

2017
If you want to take advantage of the parsers ability to fetch
@@ -23,7 +20,6 @@ you can manually create the parent objects and link them to the docstring:
2320

2421
```python
2522
from griffe.dataclasses import Docstring, Function, Parameters, Parameter, ParameterKind
26-
from griffe.docstrings.parsers import Parser, parse
2723

2824
function = Function(
2925
"func",
@@ -40,7 +36,7 @@ Parameters:
4036
param2: Description.
4137
"""
4238
docstring = Docstring(text, lineno=1, parent=function)
43-
parsed = parse(docstring, Parser.google)
39+
parsed = docstring.parse("google")
4440
```
4541

4642
With this the parser will fetch the `str` and `int` annotations

0 commit comments

Comments
 (0)