1
1
import re
2
2
3
+ import sphinx .util .logging
4
+
3
5
from sphinx .ext import autodoc
4
6
5
7
from ._objects import (
13
15
)
14
16
15
17
18
+ LOGGER = sphinx .util .logging .getLogger (__name__ )
19
+
20
+
16
21
class AutoapiDocumenter (autodoc .Documenter ):
17
22
def get_attr (self , obj , name , * defargs ):
18
23
attrgetters = self .env .app .registry .autodoc_attrgettrs
@@ -33,11 +38,18 @@ def get_attr(self, obj, name, *defargs):
33
38
34
39
raise AttributeError (name )
35
40
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
+ """
37
49
max_splits = self .fullname .count ("." )
50
+ objects = self .env .autoapi_objects
38
51
for num_splits in range (max_splits , - 1 , - 1 ):
39
52
path_stack = list (reversed (self .fullname .rsplit ("." , num_splits )))
40
- objects = self .env .autoapi_objects
41
53
parent = None
42
54
current = objects .get (path_stack .pop ())
43
55
while current and path_stack :
@@ -50,6 +62,9 @@ def import_object(self):
50
62
self ._method_parent = parent
51
63
return True
52
64
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 ()
53
68
return False
54
69
55
70
def get_real_modname (self ):
0 commit comments