22
33You can use Griffe to parse arbitrary docstrings.
44You 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,
97choosing the parsing-style to use:
108
119``` python
1210from griffe.dataclasses import Docstring
13- from griffe.docstrings.parsers import Parser, parse
1411
1512text = " Hello I'm a docstring!"
1613docstring = Docstring(text, lineno = 1 )
17- parsed = parse( docstring, Parser. google)
14+ parsed = docstring.parse( " google" )
1815```
1916
2017If 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
2522from griffe.dataclasses import Docstring, Function, Parameters, Parameter, ParameterKind
26- from griffe.docstrings.parsers import Parser, parse
2723
2824function = Function(
2925 " func" ,
@@ -40,7 +36,7 @@ Parameters:
4036 param2: Description.
4137"""
4238docstring = Docstring(text, lineno = 1 , parent = function)
43- parsed = parse( docstring, Parser. google)
39+ parsed = docstring.parse( " google" )
4440```
4541
4642With this the parser will fetch the ` str ` and ` int ` annotations
0 commit comments