22
33from __future__ import annotations
44
5+ import copy
56import glob
67import os
78import posixpath
89import re
910import sys
1011from collections import ChainMap
1112from contextlib import suppress
12- from typing import Any , BinaryIO , Iterator , Optional , Tuple
13+ from typing import Any , BinaryIO , Iterator , Mapping , Optional , Tuple
1314
1415from griffe .agents .extensions import load_extensions
1516from griffe .collections import LinesCollection , ModulesCollection
@@ -78,6 +79,16 @@ class PythonHandler(BaseHandler):
7879 "separate_signature" : False ,
7980 "line_length" : 60 ,
8081 "merge_init_into_class" : False ,
82+ "show_docstring_attributes" : True ,
83+ "show_docstring_description" : True ,
84+ "show_docstring_examples" : True ,
85+ "show_docstring_other_parameters" : True ,
86+ "show_docstring_parameters" : True ,
87+ "show_docstring_raises" : True ,
88+ "show_docstring_receives" : True ,
89+ "show_docstring_returns" : True ,
90+ "show_docstring_warns" : True ,
91+ "show_docstring_yields" : True ,
8192 "show_source" : True ,
8293 "show_bases" : True ,
8394 "show_submodules" : False ,
@@ -118,6 +129,16 @@ class PythonHandler(BaseHandler):
118129 line_length (int): Maximum line length when formatting code/signatures. Default: `60`.
119130 merge_init_into_class (bool): Whether to merge the `__init__` method into the class' signature and docstring. Default: `False`.
120131 show_if_no_docstring (bool): Show the object heading even if it has no docstring or children with docstrings. Default: `False`.
132+ show_docstring_attributes (bool): Whether to display the "Attributes" section in the object's docstring. Default: `True`.
133+ show_docstring_description (bool): Whether to display the textual block (including admonitions) in the object's docstring. Default: `True`.
134+ show_docstring_examples (bool): Whether to display the "Examples" section in the object's docstring. Default: `True`.
135+ show_docstring_other_parameters (bool): Whether to display the "Other Parameters" section in the object's docstring. Default: `True`.
136+ show_docstring_parameters (bool): Whether to display the "Parameters" section in the object's docstring. Default: `True`.
137+ show_docstring_raises (bool): Whether to display the "Raises" section in the object's docstring. Default: `True`.
138+ show_docstring_receives (bool): Whether to display the "Receives" section in the object's docstring. Default: `True`.
139+ show_docstring_returns (bool): Whether to display the "Returns" section in the object's docstring. Default: `True`.
140+ show_docstring_warns (bool): Whether to display the "Warns" section in the object's docstring. Default: `True`.
141+ show_docstring_yields (bool): Whether to display the "Yields" section in the object's docstring. Default: `True`.
121142
122143 Attributes: Signatures/annotations options:
123144 annotations_path (str): The verbosity for annotations path: `brief` (recommended), or `source` (as written in the source). Default: `"brief"`.
@@ -168,6 +189,7 @@ def load_inventory(
168189 in_file : BinaryIO ,
169190 url : str ,
170191 base_url : Optional [str ] = None ,
192+ domains : list [str ] | None = None ,
171193 ** kwargs : Any ,
172194 ) -> Iterator [Tuple [str , str ]]:
173195 """Yield items and their URLs from an inventory file streamed from `in_file`.
@@ -178,24 +200,28 @@ def load_inventory(
178200 in_file: The binary file-like object to read the inventory from.
179201 url: The URL that this file is being streamed from (used to guess `base_url`).
180202 base_url: The URL that this inventory's sub-paths are relative to.
203+ domains: A list of domain strings to filter the inventory by, when not passed, "py" will be used.
181204 **kwargs: Ignore additional arguments passed from the config.
182205
183206 Yields:
184207 Tuples of (item identifier, item URL).
185208 """
209+ domains = domains or ["py" ]
186210 if base_url is None :
187211 base_url = posixpath .dirname (url )
188212
189- for item in Inventory .parse_sphinx (in_file , domain_filter = ( "py" ,) ).values (): # noqa: WPS526
213+ for item in Inventory .parse_sphinx (in_file , domain_filter = domains ).values (): # noqa: WPS526
190214 yield item .name , posixpath .join (base_url , item .uri )
191215
192- def collect (self , identifier : str , config : dict ) -> CollectorItem : # noqa: D102,WPS231
216+ def collect (self , identifier : str , config : Mapping [ str , Any ] ) -> CollectorItem : # noqa: D102,WPS231
193217 module_name = identifier .split ("." , 1 )[0 ]
194218 unknown_module = module_name not in self ._modules_collection
195219 if config .get ("fallback" , False ) and unknown_module :
196220 raise CollectionError ("Not loading additional modules during fallback" )
197221
198- final_config = ChainMap (config , self .default_config )
222+ # See: https://github.com/python/typeshed/issues/8430
223+ mutable_config = dict (copy .deepcopy (config ))
224+ final_config = ChainMap (mutable_config , self .default_config )
199225 parser_name = final_config ["docstring_style" ]
200226 parser_options = final_config ["docstring_options" ]
201227 parser = parser_name and Parser (parser_name )
@@ -216,7 +242,7 @@ def collect(self, identifier: str, config: dict) -> CollectorItem: # noqa: D102
216242
217243 unresolved , iterations = loader .resolve_aliases (implicit = False , external = False )
218244 if unresolved :
219- logger .warning (f"{ len (unresolved )} aliases were still unresolved after { iterations } iterations" )
245+ logger .debug (f"{ len (unresolved )} aliases were still unresolved after { iterations } iterations" )
220246 logger .debug (f"Unresolved aliases: { ', ' .join (sorted (unresolved ))} " )
221247
222248 try :
@@ -232,8 +258,10 @@ def collect(self, identifier: str, config: dict) -> CollectorItem: # noqa: D102
232258
233259 return doc_object
234260
235- def render (self , data : CollectorItem , config : dict ) -> str : # noqa: D102 (ignore missing docstring)
236- final_config = ChainMap (config , self .default_config )
261+ def render (self , data : CollectorItem , config : Mapping [str , Any ]) -> str : # noqa: D102 (ignore missing docstring)
262+ # See https://github.com/python/typeshed/issues/8430
263+ mutabled_config = dict (copy .deepcopy (config ))
264+ final_config = ChainMap (mutabled_config , self .default_config )
237265
238266 template = self .env .get_template (f"{ data .kind .value } .html" )
239267
0 commit comments