1414* Fix the intersphinx mappings to the Django documentation
1515 (see :mod:`~sphinxcontrib_django.docstrings.patches`)
1616"""
17+ from __future__ import annotations
18+
1719import importlib
1820import os
21+ from typing import TYPE_CHECKING
1922
2023import django
2124from sphinx .errors import ConfigError
2730from .data import improve_data_docstring
2831from .methods import improve_method_docstring
2932
33+ if TYPE_CHECKING :
34+ from sphinx .application import Sphinx
35+ from sphinx .config import Config
36+ from sphinx .ext .autodoc import Options
37+
3038
31- def setup (app ) :
39+ def setup (app : Sphinx ) -> dict :
3240 """
3341 Allow this package to be used as Sphinx extension.
3442
@@ -43,7 +51,6 @@ def setup(app):
4351 :event:`config-inited` event.
4452
4553 :param app: The Sphinx application object
46- :type app: ~sphinx.application.Sphinx
4754 """
4855 from .patches import patch_django_for_autodoc
4956
@@ -86,18 +93,16 @@ def setup(app):
8693 }
8794
8895
89- def setup_django (app , config ) :
96+ def setup_django (app : Sphinx , config : Config ) -> None :
9097 """
9198 This function calls :func:`django.setup` so it doesn't have to be done in the app's
9299 ``conf.py``.
93100
94101 Called on the :event:`config-inited` event.
95102
96103 :param app: The Sphinx application object
97- :type app: ~sphinx.application.Sphinx
98104
99105 :param config: The Sphinx configuration
100- :type config: ~sphinx.config.Config
101106
102107 :raises ~sphinx.errors.ConfigError: If setting ``django_settings`` is not set correctly
103108 """
@@ -121,27 +126,20 @@ def setup_django(app, config):
121126 app .emit ("django-configured" )
122127
123128
124- def autodoc_skip (app , what , name , obj , skip , options ):
129+ def autodoc_skip (
130+ app : Sphinx , what : str , name : str , obj : object , options : Options , lines : list [str ]
131+ ) -> bool | None :
125132 """
126133 Hook to tell autodoc to include or exclude certain fields (see :event:`autodoc-skip-member`).
127134
128135 Sadly, it doesn't give a reference to the parent object,
129136 so only the ``name`` can be used for referencing.
130137
131138 :param app: The Sphinx application object
132- :type app: ~sphinx.application.Sphinx
133-
134139 :param what: The parent type, ``class`` or ``module``
135- :type what: str
136-
137140 :param name: The name of the child method/attribute.
138- :type name: str
139-
140141 :param obj: The child value (e.g. a method, dict, or module reference)
141- :type obj: object
142-
143142 :param options: The current autodoc settings.
144- :type options: dict
145143 """
146144 if name in EXCLUDE_MEMBERS :
147145 return True
@@ -152,33 +150,24 @@ def autodoc_skip(app, what, name, obj, skip, options):
152150 return None
153151
154152
155- def improve_docstring (app , what , name , obj , options , lines ):
153+ def improve_docstring (
154+ app : Sphinx , what : str , name : str , obj : object , options : Options , lines : list [str ]
155+ ) -> list [str ]:
156156 """
157157 Hook to improve the autodoc docstrings for Django models
158158 (see :event:`autodoc-process-docstring`).
159159
160160 :param what: The type of the object which the docstring belongs to (one of ``module``,
161161 ``class``, ``exception``, ``function``, ``method`` and ``attribute``)
162- :type what: str
163-
164162 :param name: The fully qualified name of the object
165- :type name: str
166-
167163 :param obj: The documented object
168- :type obj: object
169-
170164 :param options: The options given to the directive: an object with attributes
171165 ``inherited_members``, ``undoc_members``, ``show_inheritance`` and ``noindex``
172166 that are ``True`` if the flag option of same name was given to the auto
173167 directive
174- :type options: object
175-
176168 :param lines: A list of strings – the lines of the processed docstring – that the event
177169 handler can modify in place to change what Sphinx puts into the output.
178- :type lines: list [ str ]
179-
180170 :return: The modified list of lines
181- :rtype: list [ str ]
182171 """
183172 if what == "class" :
184173 improve_class_docstring (app , obj , lines )
0 commit comments