11import re
22
3+ import sphinx .util .logging
4+
35from sphinx .ext import autodoc
46
57from ._objects import (
1315)
1416
1517
18+ LOGGER = sphinx .util .logging .getLogger (__name__ )
19+
20+
1621class AutoapiDocumenter (autodoc .Documenter ):
1722 def get_attr (self , obj , name , * defargs ):
1823 attrgetters = self .env .app .registry .autodoc_attrgettrs
@@ -33,11 +38,18 @@ def get_attr(self, obj, name, *defargs):
3338
3439 raise AttributeError (name )
3540
36- def import_object (self ):
41+ def import_object (self ) -> bool :
42+ """Imports and sets the object to be documented.
43+
44+ The object is searched in the autoapi_objects dict based on the fullname attribute of the documenter.
45+
46+ Returns:
47+ bool: True if the object was successfully imported and set, False otherwise.
48+ """
3749 max_splits = self .fullname .count ("." )
50+ objects = self .env .autoapi_objects
3851 for num_splits in range (max_splits , - 1 , - 1 ):
3952 path_stack = list (reversed (self .fullname .rsplit ("." , num_splits )))
40- objects = self .env .autoapi_objects
4153 parent = None
4254 current = objects .get (path_stack .pop ())
4355 while current and path_stack :
@@ -50,6 +62,9 @@ def import_object(self):
5062 self ._method_parent = parent
5163 return True
5264
65+ # If we get here, the object was not found. Emit a warning as autodoc does.
66+ LOGGER .warning ("Failed to import %s '%s' [autoapi.import]" , self .directivetype , self .fullname , type = "autoapi" , subtype = "import" )
67+ self .env .note_reread ()
5368 return False
5469
5570 def get_real_modname (self ):
0 commit comments