1919from sphinx .ext .autodoc ._docstrings import _prepare_docstrings , _process_docstrings
2020from sphinx .ext .autodoc ._member_finder import _document_members
2121from sphinx .ext .autodoc ._renderer import _add_content , _directive_header_lines
22- from sphinx .ext .autodoc .importer import _load_object_by_name
2322from sphinx .ext .autodoc .mock import ismock
2423from sphinx .locale import _ , __
2524from sphinx .pycode import ModuleAnalyzer
@@ -98,13 +97,9 @@ def __init__(
9897 self .get_attr = directive .get_attr
9998 self .orig_name = orig_name
10099 self .indent : Final = indent
101- # the parent/owner of the object to document
102- self .parent : Any = None
103100 # the module analyzer to get at attribute docs, or None
104101 self .analyzer : ModuleAnalyzer | None = None
105102
106- self ._load_object_has_been_called = False
107-
108103 if isinstance (self , ModuleDocumenter ):
109104 self .options = self .options .merge_member_options ()
110105 elif isinstance (self , ClassDocumenter ):
@@ -122,35 +117,6 @@ def add_line(self, line: str, source: str, *lineno: int, indent: str) -> None:
122117 else :
123118 self .directive .result .append ('' , source , * lineno )
124119
125- def _load_object_by_name (self ) -> Literal [True ] | None :
126- """Import the object given by *self.orig_name*.
127-
128- Returns True if parsing and resolving was successful, otherwise None.
129- """
130- if self ._load_object_has_been_called :
131- return True
132-
133- ret = _load_object_by_name (
134- name = self .orig_name ,
135- objtype = self .objtype , # type: ignore[arg-type]
136- mock_imports = self .config .autodoc_mock_imports ,
137- type_aliases = self .config .autodoc_type_aliases ,
138- current_document = self ._current_document ,
139- config = self .config ,
140- env = self .env ,
141- events = self ._events ,
142- get_attr = self .get_attr ,
143- options = self .options ,
144- )
145- if ret is None :
146- return None
147- props , parent = ret
148-
149- self .props = props
150- self .parent = parent
151- self ._load_object_has_been_called = True
152- return True
153-
154120 def add_directive_header (self , * , indent : str ) -> None :
155121 """Add the directive header and options to the generated content."""
156122 domain_name = getattr (self , 'domain' , 'py' )
@@ -286,41 +252,29 @@ def _assemble_more_content(
286252
287253 return more_content
288254
289- def generate (
255+ def _generate (
290256 self ,
291257 more_content : StringList | None = None ,
292258 real_modname : str | None = None ,
293259 check_module : bool = False ,
294260 all_members : bool = False ,
295261 ) -> None :
296- """Generate reST for the object given by *self.orig_name *, and possibly for
262+ """Generate reST for the object given by *self.props *, and possibly for
297263 its members.
298264
299265 If *more_content* is given, include that content. If *real_modname* is
300266 given, use that module name to find attribute docs. If *check_module* is
301267 True, only generate if the object is defined in the module name it is
302268 imported from. If *all_members* is True, document all members.
303269 """
304- if isinstance ( self , ClassDocumenter ) :
270+ if self . props . obj_type in { 'class' , 'exception' } :
305271 # Do not pass real_modname and use the name from the __module__
306272 # attribute of the class.
307273 # If a class gets imported into the module real_modname
308274 # the analyzer won't find the source of the class, if
309275 # it looks in real_modname.
310276 real_modname = None
311277
312- if self ._load_object_by_name () is None :
313- return
314-
315- self ._generate (more_content , real_modname , check_module , all_members )
316-
317- def _generate (
318- self ,
319- more_content : StringList | None = None ,
320- real_modname : str | None = None ,
321- check_module : bool = False ,
322- all_members : bool = False ,
323- ) -> None :
324278 # If there is no real module defined, figure out which to use.
325279 # The real module is used in the module analyzer to look up the module
326280 # where the attribute documentation would actually be found in.
0 commit comments