1919from sphinx .environment import BuildEnvironment
2020from sphinx .ext .autodoc import Options
2121from sphinx .ext .autodoc .mock import mock
22+ from sphinx .ext .napoleon .docstring import GoogleDocstring
2223from sphinx .util import logging
2324from sphinx .util .inspect import signature as sphinx_signature
2425from sphinx .util .inspect import stringify_signature
@@ -808,6 +809,18 @@ def fix_autodoc_typehints_for_overloaded_methods() -> None:
808809 del MethodDocumenter .format_signature
809810
810811
812+ def patched_lookup_annotation (* _args : Any ) -> str : # noqa: U101
813+ """GoogleDocstring._lookup_annotation sometimes adds incorrect type
814+ annotations to constructor parameters (and otherwise does nothing). Disable
815+ it so we can handle this on our own.
816+ """
817+ return ""
818+
819+
820+ def patch_google_docstring_lookup_annotation () -> None :
821+ GoogleDocstring ._lookup_annotation = patched_lookup_annotation # type: ignore[assignment]
822+
823+
811824def setup (app : Sphinx ) -> dict [str , bool ]:
812825 app .add_config_value ("always_document_param_types" , False , "html" )
813826 app .add_config_value ("typehints_fully_qualified" , False , "env" )
@@ -823,6 +836,7 @@ def setup(app: Sphinx) -> dict[str, bool]:
823836 app .connect ("autodoc-process-docstring" , process_docstring )
824837 fix_autodoc_typehints_for_overloaded_methods ()
825838 patch_attribute_handling (app )
839+ patch_google_docstring_lookup_annotation ()
826840 return {"parallel_read_safe" : True }
827841
828842
0 commit comments