1212import traceback
1313from collections import ChainMap
1414from subprocess import PIPE , Popen
15- from typing import TYPE_CHECKING , Any , BinaryIO , Iterator
15+ from typing import TYPE_CHECKING , Any , BinaryIO , ClassVar , Iterator , Mapping , MutableMapping
1616
1717from mkdocstrings_handlers .python .rendering import (
1818 do_brief_xref ,
@@ -48,7 +48,7 @@ class PythonHandler(BaseHandler):
4848 enable_inventory : bool = True
4949
5050 fallback_theme = "material"
51- fallback_config = {"docstring_style" : "markdown" , "filters" : ["!.*" ]}
51+ fallback_config : ClassVar [ dict ] = {"docstring_style" : "markdown" , "filters" : ["!.*" ]}
5252 """The configuration used when falling back to re-collecting an object to get its anchor.
5353
5454 This configuration is used in [`Handlers.get_anchors`][mkdocstrings.handlers.base.Handlers.get_anchors].
@@ -63,7 +63,7 @@ class PythonHandler(BaseHandler):
6363 which we know will not generate any warnings.
6464 """
6565
66- default_config : dict = {
66+ default_config : ClassVar [ dict ] = {
6767 "filters" : ["!^_[^_]" ],
6868 "show_root_heading" : False ,
6969 "show_root_toc_entry" : True ,
@@ -122,11 +122,11 @@ class PythonHandler(BaseHandler):
122122
123123 def __init__ (
124124 self ,
125- * args ,
125+ * args : Any ,
126126 setup_commands : list [str ] | None = None ,
127127 config_file_path : str | None = None ,
128128 paths : list [str ] | None = None ,
129- ** kwargs ,
129+ ** kwargs : Any ,
130130 ) -> None :
131131 """Initialize the handler.
132132
@@ -153,7 +153,7 @@ def __init__(
153153 search_paths = []
154154 for path in paths :
155155 if not os .path .isabs (path ) and config_file_path :
156- path = os .path .abspath (os .path .join (os .path .dirname (config_file_path ), path ))
156+ path = os .path .abspath (os .path .join (os .path .dirname (config_file_path ), path )) # noqa: PLW2901
157157 if path not in search_paths :
158158 search_paths .append (path )
159159 self ._paths = search_paths
@@ -188,7 +188,7 @@ def __init__(
188188 cmd = [sys .executable , "-m" , "pytkdocs" , "--line-by-line" ]
189189
190190 self .process = Popen (
191- cmd ,
191+ cmd , # noqa: S603
192192 universal_newlines = True ,
193193 stdout = PIPE ,
194194 stdin = PIPE ,
@@ -203,7 +203,7 @@ def load_inventory(
203203 in_file : BinaryIO ,
204204 url : str ,
205205 base_url : str | None = None ,
206- ** kwargs ,
206+ ** kwargs : Any , # noqa: ARG003
207207 ) -> Iterator [tuple [str , str ]]:
208208 """Yield items and their URLs from an inventory file streamed from `in_file`.
209209
@@ -224,7 +224,7 @@ def load_inventory(
224224 for item in Inventory .parse_sphinx (in_file , domain_filter = ("py" ,)).values ():
225225 yield item .name , posixpath .join (base_url , item .uri )
226226
227- def collect (self , identifier : str , config : dict ) -> CollectorItem :
227+ def collect (self , identifier : str , config : MutableMapping [ str , Any ] ) -> CollectorItem :
228228 """Collect the documentation tree given an identifier and selection options.
229229
230230 In this method, we feed one line of JSON to the standard input of the subprocess that was opened
@@ -265,11 +265,11 @@ def collect(self, identifier: str, config: dict) -> CollectorItem:
265265 json_input = json .dumps ({"objects" : [{"path" : identifier , ** final_config }]})
266266
267267 logger .debug ("Writing to process' stdin" )
268- self .process .stdin .write (json_input + "\n " ) # type: ignore
269- self .process .stdin .flush () # type: ignore
268+ self .process .stdin .write (json_input + "\n " ) # type: ignore[union-attr]
269+ self .process .stdin .flush () # type: ignore[union-attr]
270270
271271 logger .debug ("Reading process' stdout" )
272- stdout = self .process .stdout .readline () # type: ignore
272+ stdout = self .process .stdout .readline () # type: ignore[union-attr]
273273
274274 logger .debug ("Loading JSON output as Python object" )
275275 try :
@@ -304,8 +304,8 @@ def teardown(self) -> None:
304304 logger .debug ("Tearing process down" )
305305 self .process .terminate ()
306306
307- def render (self , data : CollectorItem , config : dict ) -> str : # noqa: D102 (ignore missing docstring)
308- final_config = ChainMap (config , self .default_config )
307+ def render (self , data : CollectorItem , config : Mapping [ str , Any ] ) -> str : # noqa: D102 (ignore missing docstring)
308+ final_config = ChainMap (config , self .default_config ) # type: ignore[arg-type]
309309
310310 template = self .env .get_template (f"{ data ['category' ]} .html" )
311311
@@ -348,7 +348,7 @@ def get_handler(
348348 setup_commands : list [str ] | None = None ,
349349 config_file_path : str | None = None ,
350350 paths : list [str ] | None = None ,
351- ** config : Any ,
351+ ** config : Any , # noqa: ARG001
352352) -> PythonHandler :
353353 """Simply return an instance of `PythonHandler`.
354354
0 commit comments