88import os
99import sys
1010import pkgutil
11- from typing import Any , get_type_hints
11+ from typing import get_type_hints
12+
13+ from sphinx .errors import PycodeError
14+ from sphinx .pycode import ModuleAnalyzer
15+ from sphinx .application import Sphinx
16+ from sphinx .ext .autodoc import Documenter
17+ from sphinx_toolbox .more_autodoc .autotypeddict import TypedDictDocumenter
1218
1319# Add the src directory to the path so we can import the package
1420sys .path .insert (0 , os .path .abspath ("../src" ))
@@ -74,9 +80,6 @@ def _patch_autotypeddict_inherited_docstrings() -> None:
7480
7581 Upstream bug: https://github.com/sphinx-doc/sphinx/issues/9290
7682 """
77- from sphinx .errors import PycodeError
78- from sphinx .pycode import ModuleAnalyzer
79- from sphinx_toolbox .more_autodoc .autotypeddict import TypedDictDocumenter
8083
8184 def _collect_field_docstrings (cls : type ) -> dict [str , list [str ]]:
8285 result : dict [str , list [str ]] = {}
@@ -101,9 +104,9 @@ def _walk(klass: type) -> None:
101104
102105 def _patched_sort_members (
103106 self : TypedDictDocumenter ,
104- documenters : list [tuple [Any , bool ]],
107+ documenters : list [tuple [Documenter , bool ]],
105108 order : str ,
106- ) -> list [tuple [Any , bool ]]:
109+ ) -> list [tuple [Documenter , bool ]]:
107110 documenters = super (TypedDictDocumenter , self ).sort_members (documenters , order )
108111 docstrings = _collect_field_docstrings (self .object )
109112
@@ -122,12 +125,12 @@ def _patched_sort_members(
122125 if required_keys :
123126 self .add_line ("" , sourcename )
124127 self .add_line (":Required Keys:" , sourcename )
125- self .document_keys (required_keys , types , docstrings ) # pyright: ignore[reportUnknownMemberType]
128+ self .document_keys (required_keys , types , docstrings )
126129 self .add_line ("" , sourcename )
127130 if optional_keys :
128131 self .add_line ("" , sourcename )
129132 self .add_line (":Optional Keys:" , sourcename )
130- self .document_keys (optional_keys , types , docstrings ) # pyright: ignore[reportUnknownMemberType]
133+ self .document_keys (optional_keys , types , docstrings )
131134 self .add_line ("" , sourcename )
132135
133136 return []
@@ -141,7 +144,7 @@ def _patched_sort_members(
141144# -- Dynamic type documentation ----------------------------------------------
142145
143146
144- def _inject_type_submodules (_app : Any , docname : str , source : list [str ]) -> None :
147+ def _inject_type_submodules (_app : Sphinx , docname : str , source : list [str ]) -> None :
145148 """Auto-generate automodule directives for all type submodules.
146149
147150 Replaces the ``.. auto-all-types::`` placeholder in types.rst with
@@ -165,7 +168,7 @@ def _inject_type_submodules(_app: Any, docname: str, source: list[str]) -> None:
165168 source [0 ] = source [0 ].replace (".. auto-all-types::" , "\n " .join (directives ))
166169
167170
168- def setup (app : Any ) -> None :
171+ def setup (app : Sphinx ) -> None :
169172 app .connect ("source-read" , _inject_type_submodules )
170173
171174
0 commit comments