33"""
44from __future__ import annotations
55
6+ from typing import TYPE_CHECKING
7+
68from django import forms
79from django .db import models
8- from sphinx .application import Sphinx
910from sphinx .pycode import ModuleAnalyzer
1011
1112from .field_utils import get_field_type , get_field_verbose_name
1213
14+ if TYPE_CHECKING :
15+ import django
16+ import sphinx
17+
1318
14- def improve_class_docstring (app : Sphinx , cls : type , lines : list [str ]) -> None :
19+ def improve_class_docstring (
20+ app : sphinx .application .Sphinx , cls : type , lines : list [str ]
21+ ) -> None :
1522 """
1623 Improve the documentation of a class if it's a Django model or form
1724
@@ -25,7 +32,9 @@ def improve_class_docstring(app: Sphinx, cls: type, lines: list[str]) -> None:
2532 improve_form_docstring (cls , lines )
2633
2734
28- def improve_model_docstring (app : Sphinx , model : models .Model , lines : list [str ]) -> None :
35+ def improve_model_docstring (
36+ app : sphinx .application .Sphinx , model : django .db .models .Model , lines : list [str ]
37+ ) -> None :
2938 """
3039 Improve the documentation of a Django :class:`~django.db.models.Model` subclass.
3140
@@ -109,7 +118,9 @@ def improve_model_docstring(app: Sphinx, model: models.Model, lines: list[str])
109118 lines .append ("" )
110119
111120
112- def add_db_table_name (app : Sphinx , model : models .Model , lines : list [str ]) -> None :
121+ def add_db_table_name (
122+ app : sphinx .application .Sphinx , model : django .db .models .Model , lines : list [str ]
123+ ) -> None :
113124 """
114125 Format and add table name by extension configuration.
115126
@@ -126,7 +137,7 @@ def add_db_table_name(app: Sphinx, model: models.Model, lines: list[str]) -> Non
126137
127138
128139def add_model_parameters (
129- fields : list [models .Field ], lines : list [str ], field_docs : dict
140+ fields : list [django . db . models .Field ], lines : list [str ], field_docs : dict
130141) -> None :
131142 """
132143 Add the given fields as model parameter with the ``:param:`` directive
@@ -151,7 +162,7 @@ def add_model_parameters(
151162 lines .append (f":type { field .name } : { get_field_type (field , include_role = False )} " )
152163
153164
154- def improve_form_docstring (form : forms .Form , lines : list [str ]) -> None :
165+ def improve_form_docstring (form : django . forms .Form , lines : list [str ]) -> None :
155166 """
156167 Improve the documentation of a Django :class:`~django.forms.Form` class.
157168 This highlights the available fields in the form.
0 commit comments