33It collects data with [`pytkdocs`](https://github.com/pawamoy/pytkdocs).
44"""
55
6- from __future__ import annotations
7-
86import json
97import os
108import posixpath
119import sys
1210import traceback
1311from collections import ChainMap
1412from subprocess import PIPE , Popen
15- from typing import TYPE_CHECKING , Any , BinaryIO , ClassVar , Iterator , Mapping , MutableMapping
13+ from typing import Any , BinaryIO , ClassVar , Iterator , List , Mapping , MutableMapping , Optional , Tuple
14+
15+ from markdown import Markdown
16+ from mkdocstrings .extension import PluginError
17+ from mkdocstrings .handlers .base import BaseHandler , CollectionError , CollectorItem
18+ from mkdocstrings .inventory import Inventory
19+ from mkdocstrings .loggers import get_logger
1620
1721from mkdocstrings_handlers .python .rendering import (
1822 do_brief_xref ,
2226 sort_object ,
2327)
2428
25- from mkdocstrings .extension import PluginError
26- from mkdocstrings .handlers .base import BaseHandler , CollectionError , CollectorItem
27- from mkdocstrings .inventory import Inventory
28- from mkdocstrings .loggers import get_logger
29-
30- if TYPE_CHECKING :
31- from markdown import Markdown
32-
3329# TODO: add a deprecation warning once the new handler handles 95% of use-cases
3430
3531logger = get_logger (__name__ )
@@ -123,9 +119,9 @@ class PythonHandler(BaseHandler):
123119 def __init__ (
124120 self ,
125121 * args : Any ,
126- setup_commands : list [ str ] | None = None ,
127- config_file_path : str | None = None ,
128- paths : list [ str ] | None = None ,
122+ setup_commands : Optional [ List [ str ]] = None ,
123+ config_file_path : Optional [ str ] = None ,
124+ paths : Optional [ List [ str ]] = None ,
129125 ** kwargs : Any ,
130126 ) -> None :
131127 """Initialize the handler.
@@ -187,8 +183,8 @@ def __init__(
187183 else :
188184 cmd = [sys .executable , "-m" , "pytkdocs" , "--line-by-line" ]
189185
190- self .process = Popen (
191- cmd , # noqa: S603
186+ self .process = Popen ( # noqa: S603
187+ cmd ,
192188 universal_newlines = True ,
193189 stdout = PIPE ,
194190 stdin = PIPE ,
@@ -202,9 +198,9 @@ def load_inventory(
202198 cls ,
203199 in_file : BinaryIO ,
204200 url : str ,
205- base_url : str | None = None ,
201+ base_url : Optional [ str ] = None ,
206202 ** kwargs : Any , # noqa: ARG003
207- ) -> Iterator [tuple [str , str ]]:
203+ ) -> Iterator [Tuple [str , str ]]:
208204 """Yield items and their URLs from an inventory file streamed from `in_file`.
209205
210206 This implements mkdocstrings' `load_inventory` "protocol" (see plugin.py).
@@ -328,7 +324,7 @@ def render(self, data: CollectorItem, config: Mapping[str, Any]) -> str: # noqa
328324 ** {"config" : final_config , data ["category" ]: data , "heading_level" : heading_level , "root" : True },
329325 )
330326
331- def get_anchors (self , data : CollectorItem ) -> tuple [str , ...]: # noqa: D102 (ignore missing docstring)
327+ def get_anchors (self , data : CollectorItem ) -> Tuple [str , ...]: # noqa: D102 (ignore missing docstring)
332328 try :
333329 return (data ["path" ],)
334330 except KeyError :
@@ -344,10 +340,10 @@ def update_env(self, md: Markdown, config: dict) -> None: # noqa: D102 (ignore
344340
345341def get_handler (
346342 theme : str ,
347- custom_templates : str | None = None ,
348- setup_commands : list [ str ] | None = None ,
349- config_file_path : str | None = None ,
350- paths : list [ str ] | None = None ,
343+ custom_templates : Optional [ str ] = None ,
344+ setup_commands : Optional [ List [ str ]] = None ,
345+ config_file_path : Optional [ str ] = None ,
346+ paths : Optional [ List [ str ]] = None ,
351347 ** config : Any , # noqa: ARG001
352348) -> PythonHandler :
353349 """Simply return an instance of `PythonHandler`.
0 commit comments