1616from sphinx .util .typing import restify , stringify_annotation
1717
1818if TYPE_CHECKING :
19- from collections .abc import Iterator , Mapping
19+ from collections .abc import Iterator
2020 from typing import Literal
2121
2222 from sphinx .config import Config
3232
3333def _generate_directives (
3434 more_content : StringList | None = None ,
35- real_modname : str | None = None ,
35+ parent_modname : str | None = None ,
3636 check_module : bool = False ,
3737 all_members : bool = False ,
3838 * ,
@@ -49,26 +49,23 @@ def _generate_directives(
4949) -> None :
5050 """Generate reST for the object given by *props*, and possibly for its members.
5151
52- If *more_content* is given, include that content. If *real_modname * is
52+ If *more_content* is given, include that content. If *parent_modname * is
5353 given, use that module name to find attribute docs. If *check_module* is
5454 True, only generate if the object is defined in the module name it is
5555 imported from. If *all_members* is True, document all members.
5656 """
57- # If there is no real module defined , figure out which to use.
57+ # If there is no parent module specified , figure out which to use.
5858 # The real module is used in the module analyzer to look up the module
5959 # where the attribute documentation would actually be found in.
6060 # This is used for situations where you have a module that collects the
6161 # functions and classes of internal submodules.
62- guess_modname = props ._obj___module__ or props .module_name
63- if props .obj_type in {'class' , 'exception' }:
64- # Do not pass real_modname and use the name from the __module__
65- # attribute of the class.
66- # If a class gets imported into the module real_modname
67- # the analyzer won't find the source of the class, if
68- # it looks in real_modname.
69- real_modname = guess_modname
62+ if parent_modname is None or props .obj_type in {'class' , 'exception' }:
63+ # If a class gets imported into the module ``parent_modname``
64+ # the analyzer won't find the source of the class,
65+ # if it looks in ``parent_modname``.
66+ real_modname = props .canonical_module_name
7067 else :
71- real_modname = real_modname or guess_modname
68+ real_modname = parent_modname
7269
7370 # try to also get a source code analyzer for attribute docs
7471 try :
@@ -95,10 +92,10 @@ def _generate_directives(
9592 ):
9693 record_dependencies .add (module_spec .origin )
9794
98- if real_modname != guess_modname :
95+ if real_modname != props . canonical_module_name :
9996 # Add module to dependency list if target object is defined in other module.
10097 try :
101- srcname , _ = ModuleAnalyzer .get_module_source (guess_modname )
98+ srcname , _ = ModuleAnalyzer .get_module_source (props . canonical_module_name )
10299 record_dependencies .add (str (srcname ))
103100 except PycodeError :
104101 pass
@@ -123,10 +120,8 @@ def _generate_directives(
123120 analyzer_source = '' if analyzer is None else analyzer .srcname
124121 _add_directive_lines (
125122 more_content = more_content ,
126- attr_docs = {} if analyzer is None else analyzer .attr_docs ,
127123 is_final = analyzer is not None and props .dotted_parts in analyzer .finals ,
128124 config = config ,
129- events = events ,
130125 indent = indent ,
131126 options = options ,
132127 props = props ,
@@ -156,10 +151,8 @@ def _generate_directives(
156151def _add_directive_lines (
157152 * ,
158153 more_content : StringList | None ,
159- attr_docs : Mapping [tuple [str , str ], list [str ]],
160154 is_final : bool ,
161155 config : Config ,
162- events : EventManager ,
163156 indent : str ,
164157 options : _AutoDocumenterOptions ,
165158 props : _ItemProperties ,
@@ -244,7 +237,7 @@ def _document_members(
244237 events = events ,
245238 get_attr = get_attr ,
246239 options = options ,
247- real_modname = real_modname ,
240+ parent_modname = real_modname ,
248241 props = props ,
249242 )
250243
@@ -261,7 +254,7 @@ def _document_members(
261254 # whatever objects we deduced should not have changed.
262255 _generate_directives (
263256 more_content = None ,
264- real_modname = real_modname ,
257+ parent_modname = real_modname ,
265258 check_module = members_check_module and not is_attr ,
266259 all_members = True ,
267260 config = config ,
0 commit comments